Merge branch 'PHP-8.3'

This commit is contained in:
Jakub Zelenka 2024-04-14 14:27:49 +01:00
commit ce4c8ab412
No known key found for this signature in database
GPG Key ID: 1C0779DC5C0A9DE4
2 changed files with 23 additions and 10 deletions

View File

@ -1,5 +1,5 @@
--TEST--
Test file_put_contents() function with 5GB string
Test file_put_contents() and file_get_contents() functions with 5GB string
--SKIPIF--
<?php
if (PHP_INT_SIZE < 5) {
@ -30,7 +30,7 @@ function get_system_memory(): int|float|false
if (get_system_memory() < 10 * 1024 * 1024 * 1024) {
die('skip Reason: Insufficient RAM (less than 10GB)');
}
$tmpfile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "test_file_put_contents_5gb.bin";
$tmpfile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "file_get_contents_file_put_contents_5gb.bin";
$tmpfileh = fopen($tmpfile, "wb");
if ($tmpfileh === false) {
die('skip Reason: Unable to create temporary file');
@ -45,15 +45,27 @@ if (disk_free_space(dirname($tmpfile)) < 10 * 1024 * 1024 * 1024) {
memory_limit=6G
--FILE--
<?php
$tmpfile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "test_file_put_contents_5gb.bin";
$large_string = str_repeat('a', 5 * 1024 * 1024 * 1024);
$tmpfile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "file_get_contents_file_put_contents_5gb.bin";
$large_string_len = 5 * 1024 * 1024 * 1024;
$large_string = str_repeat('a', $large_string_len);
$result = file_put_contents($tmpfile, $large_string);
if ($result !== strlen($large_string)) {
echo "Could only write $result bytes of " . strlen($large_string) . " bytes.";
if ($result !== $large_string_len) {
echo "Could only write $result bytes of $large_string_len bytes.";
var_dump(error_get_last());
} else {
echo "File written successfully.";
echo "File written successfully." . PHP_EOL;
}
unset($large_string);
$result_large_string = file_get_contents($tmpfile);
if (strlen($result_large_string) !== $large_string_len) {
echo "Could only read " . strlen($result_large_string) . " bytes of $large_string_len bytes.";
var_dump(error_get_last());
} else {
echo "File read successfully." . PHP_EOL;
}
clearstatcache(true, $tmpfile);
if (file_exists($tmpfile)) {
unlink($tmpfile);
@ -61,7 +73,8 @@ if (file_exists($tmpfile)) {
?>
--CLEAN--
<?php
@unlink(sys_get_temp_dir() . DIRECTORY_SEPARATOR . "test_file_put_contents_5gb.bin");
@unlink(sys_get_temp_dir() . DIRECTORY_SEPARATOR . "file_get_contents_file_put_contents_5gb.bin");
?>
--EXPECT--
File written successfully.
File read successfully.

View File

@ -54,7 +54,7 @@ extern int php_get_gid_by_name(const char *name, gid_t *gid);
#endif
#if defined(PHP_WIN32)
# define PLAIN_WRAP_BUF_SIZE(st) (((st) > UINT_MAX) ? UINT_MAX : (unsigned int)(st))
# define PLAIN_WRAP_BUF_SIZE(st) ((unsigned int)(st > INT_MAX ? INT_MAX : st))
#define fsync _commit
#define fdatasync fsync
#else
@ -354,7 +354,7 @@ static ssize_t php_stdiop_write(php_stream *stream, const char *buf, size_t coun
if (data->fd >= 0) {
#ifdef PHP_WIN32
ssize_t bytes_written = _write(data->fd, buf, (unsigned int)(count > INT_MAX ? INT_MAX : count));
ssize_t bytes_written = _write(data->fd, buf, PLAIN_WRAP_BUF_SIZE(count));
#else
ssize_t bytes_written = write(data->fd, buf, count);
#endif