mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Merge branch 'PHP-8.3'
This commit is contained in:
commit
ce4c8ab412
2 changed files with 23 additions and 10 deletions
|
@ -1,5 +1,5 @@
|
||||||
--TEST--
|
--TEST--
|
||||||
Test file_put_contents() function with 5GB string
|
Test file_put_contents() and file_get_contents() functions with 5GB string
|
||||||
--SKIPIF--
|
--SKIPIF--
|
||||||
<?php
|
<?php
|
||||||
if (PHP_INT_SIZE < 5) {
|
if (PHP_INT_SIZE < 5) {
|
||||||
|
@ -30,7 +30,7 @@ function get_system_memory(): int|float|false
|
||||||
if (get_system_memory() < 10 * 1024 * 1024 * 1024) {
|
if (get_system_memory() < 10 * 1024 * 1024 * 1024) {
|
||||||
die('skip Reason: Insufficient RAM (less than 10GB)');
|
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");
|
$tmpfileh = fopen($tmpfile, "wb");
|
||||||
if ($tmpfileh === false) {
|
if ($tmpfileh === false) {
|
||||||
die('skip Reason: Unable to create temporary file');
|
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
|
memory_limit=6G
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
$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";
|
||||||
$large_string = str_repeat('a', 5 * 1024 * 1024 * 1024);
|
$large_string_len = 5 * 1024 * 1024 * 1024;
|
||||||
|
|
||||||
|
$large_string = str_repeat('a', $large_string_len);
|
||||||
$result = file_put_contents($tmpfile, $large_string);
|
$result = file_put_contents($tmpfile, $large_string);
|
||||||
if ($result !== strlen($large_string)) {
|
if ($result !== $large_string_len) {
|
||||||
echo "Could only write $result bytes of " . strlen($large_string) . " bytes.";
|
echo "Could only write $result bytes of $large_string_len bytes.";
|
||||||
var_dump(error_get_last());
|
var_dump(error_get_last());
|
||||||
} else {
|
} 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);
|
clearstatcache(true, $tmpfile);
|
||||||
if (file_exists($tmpfile)) {
|
if (file_exists($tmpfile)) {
|
||||||
unlink($tmpfile);
|
unlink($tmpfile);
|
||||||
|
@ -61,7 +73,8 @@ if (file_exists($tmpfile)) {
|
||||||
?>
|
?>
|
||||||
--CLEAN--
|
--CLEAN--
|
||||||
<?php
|
<?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--
|
--EXPECT--
|
||||||
File written successfully.
|
File written successfully.
|
||||||
|
File read successfully.
|
|
@ -54,7 +54,7 @@ extern int php_get_gid_by_name(const char *name, gid_t *gid);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PHP_WIN32)
|
#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 fsync _commit
|
||||||
#define fdatasync fsync
|
#define fdatasync fsync
|
||||||
#else
|
#else
|
||||||
|
@ -354,7 +354,7 @@ static ssize_t php_stdiop_write(php_stream *stream, const char *buf, size_t coun
|
||||||
|
|
||||||
if (data->fd >= 0) {
|
if (data->fd >= 0) {
|
||||||
#ifdef PHP_WIN32
|
#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
|
#else
|
||||||
ssize_t bytes_written = write(data->fd, buf, count);
|
ssize_t bytes_written = write(data->fd, buf, count);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue