1
1
--TEST--
2
- Test file_put_contents() function with 5GB string
2
+ Test file_put_contents() and file_get_contents() functions with 5GB string
3
3
--SKIPIF--
4
4
<?php
5
5
if (PHP_INT_SIZE < 5 ) {
@@ -30,7 +30,7 @@ function get_system_memory(): int|float|false
30
30
if (get_system_memory () < 10 * 1024 * 1024 * 1024 ) {
31
31
die ('skip Reason: Insufficient RAM (less than 10GB) ' );
32
32
}
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 " ;
34
34
$ tmpfileh = fopen ($ tmpfile , "wb " );
35
35
if ($ tmpfileh === false ) {
36
36
die ('skip Reason: Unable to create temporary file ' );
@@ -45,23 +45,36 @@ if (disk_free_space(dirname($tmpfile)) < 10 * 1024 * 1024 * 1024) {
45
45
memory_limit=6G
46
46
--FILE--
47
47
<?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 );
50
52
$ 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. " ;
53
55
var_dump (error_get_last ());
54
56
} else {
55
- echo "File written successfully. " ;
57
+ echo "File written successfully. " . PHP_EOL ;
56
58
}
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
+
57
69
clearstatcache (true , $ tmpfile );
58
70
if (file_exists ($ tmpfile )) {
59
71
unlink ($ tmpfile );
60
72
}
61
73
?>
62
74
--CLEAN--
63
75
<?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 " );
65
77
?>
66
78
--EXPECT--
67
79
File written successfully.
80
+ File read successfully.
0 commit comments