PHP Project, the online encounter a strange problem, using
fwrite
Write
tmpfile()
Failed. The failure here does not mean
fwrite
Return
FALSE
, but returns
int(0)
, write 0 bytes. The code is simple as follows:
$f = tmpfile();$length = fwrite($f, '123');var_dump($length);
The output is accessed through the browser, that is, the php-fpm
mode int(0)
. I have done several other tests:
Command-line environment: the code is intact and execution can be written successfully.
php-fpm 浏览器访问
: Will be tmpfile()
replaced fopen('非 /tmp 目录', 'w+')
, php-fpm
down can be written, outputint(3)
php-fpm 浏览器访问
: Will be tmpfile()
replaced fopen('/temp/test-randomstring', 'w+')
by, outputint(0)
The current issue has been resolved in other circuitous ways, but why the write failed has not been identified. It was initially suspected to be related to the disk's remaining space on the server (only 10M left), but 1 22 tests indicated that 10M should be sufficient.
Excuse me, do you have any good to check the BUG idea? Or have you encountered a similar problem?
Updated with a new test code
$name = date("His");echo "File /tmp/$name.txt\n";shell_exec('echo "123" > /tmp/'.$name.'.txt');var_dump(file_exists('/tmp/'.$name.'.txt'));var_dump(file_get_contents('/tmp/'.$name.'.txt'));
command line execution, file write OK. php-fpm
when running, the file is always written to 0 bytes, but the file is created successfully
Reply content:
PHP project, the line encountered a strange problem, using fwrite
write tmpfile()
failed. The failure here does not mean to fwrite
return, FALSE
but to return int(0)
, write 0 bytes. The code is simple as follows:
$f = tmpfile();$length = fwrite($f, '123');var_dump($length);
The output is accessed through the browser, that is, the php-fpm
mode int(0)
. I have done several other tests:
Command-line environment: the code is intact and execution can be written successfully.
php-fpm 浏览器访问
: Will be tmpfile()
replaced fopen('非 /tmp 目录', 'w+')
, php-fpm
down can be written, outputint(3)
php-fpm 浏览器访问
: Will be tmpfile()
replaced fopen('/temp/test-randomstring', 'w+')
by, outputint(0)
The current issue has been resolved in other circuitous ways, but why the write failed has not been identified. It was initially suspected to be related to the disk's remaining space on the server (only 10M left), but 1 22 tests indicated that 10M should be sufficient.
Excuse me, do you have any good to check the BUG idea? Or have you encountered a similar problem?
Updated with a new test code
$name = date("His");echo "File /tmp/$name.txt\n";shell_exec('echo "123" > /tmp/'.$name.'.txt');var_dump(file_exists('/tmp/'.$name.'.txt'));var_dump(file_get_contents('/tmp/'.$name.'.txt'));
command line execution, file write OK. php-fpm
when running, the file is always written to 0 bytes, but the file is created successfully
Permissions
chmod 777/tmp/test-randomstring
Try it again, it's a privilege issue.
You can overwrite the file owner with Chown and chmod to the security permission.