11--TEST--
2- Test file_put_contents() function with 5GB string
2+ Test file_put_contents() and file_get_contents() functions with 5GB string
33--SKIPIF--
44<?php
55if (PHP_INT_SIZE < 5 ) {
@@ -30,7 +30,7 @@ function get_system_memory(): int|float|false
3030if (get_system_memory () < 10 * 1024 * 1024 * 1024 ) {
3131 die ('skip Reason: Insufficient RAM (less than 10GB) ' );
3232}
33- $ tmpfile = sys_get_temp_dir () . DIRECTORY_SEPARATOR . "test_file_put_contents_5gb .bin " ;
33+ $ tmpfile = sys_get_temp_dir () . DIRECTORY_SEPARATOR . "file_get_contents_file_put_contents_5gb .bin " ;
3434$ tmpfileh = fopen ($ tmpfile , "wb " );
3535if ($ tmpfileh === false ) {
3636 die ('skip Reason: Unable to create temporary file ' );
@@ -45,23 +45,36 @@ if (disk_free_space(dirname($tmpfile)) < 10 * 1024 * 1024 * 1024) {
4545memory_limit=6G
4646--FILE--
4747<?php
48- $ tmpfile = sys_get_temp_dir () . DIRECTORY_SEPARATOR . "test_file_put_contents_5gb.bin " ;
49- $ large_string = str_repeat ('a ' , 5 * 1024 * 1024 * 1024 );
48+ $ tmpfile = sys_get_temp_dir () . DIRECTORY_SEPARATOR . "file_get_contents_file_put_contents_5gb.bin " ;
49+ $ large_string_len = 5 * 1024 * 1024 * 1024 ;
50+
51+ $ large_string = str_repeat ('a ' , $ large_string_len );
5052$ result = file_put_contents ($ tmpfile , $ large_string );
51- if ($ result !== strlen ( $ large_string ) ) {
52- echo "Could only write $ result bytes of " . strlen ( $ large_string ) . " bytes. " ;
53+ if ($ result !== $ large_string_len ) {
54+ echo "Could only write $ result bytes of $ large_string_len bytes. " ;
5355 var_dump (error_get_last ());
5456} else {
55- echo "File written successfully. " ;
57+ echo "File written successfully. " . PHP_EOL ;
5658}
59+ unset($ large_string );
60+
61+ $ result_large_string = file_get_contents ($ tmpfile );
62+ if (strlen ($ result_large_string ) !== $ large_string_len ) {
63+ echo "Could only read " . strlen ($ result_large_string ) . " bytes of $ large_string_len bytes. " ;
64+ var_dump (error_get_last ());
65+ } else {
66+ echo "File read successfully. " . PHP_EOL ;
67+ }
68+
5769clearstatcache (true , $ tmpfile );
5870if (file_exists ($ tmpfile )) {
5971 unlink ($ tmpfile );
6072}
6173?>
6274--CLEAN--
6375<?php
64- @unlink (sys_get_temp_dir () . DIRECTORY_SEPARATOR . "test_file_put_contents_5gb .bin " );
76+ @unlink (sys_get_temp_dir () . DIRECTORY_SEPARATOR . "file_get_contents_file_put_contents_5gb .bin " );
6577?>
6678--EXPECT--
6779File written successfully.
80+ File read successfully.
0 commit comments