Strange problem php-fpm using fwrite to write to/tmp directory failed

Source: Internet
Author: User
PHP Project, the online encounter a strange problem, using fwriteWrite tmpfile()Failed. The failure here does not mean fwriteReturn 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:

    1. Command-line environment: the code is intact and execution can be written successfully.

    2. php-fpm 浏览器访问: Will be tmpfile() replaced fopen('非 /tmp 目录', 'w+') , php-fpm down can be written, outputint(3)

    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-fpmwhen 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:

    1. Command-line environment: the code is intact and execution can be written successfully.

    2. php-fpm 浏览器访问: Will be tmpfile() replaced fopen('非 /tmp 目录', 'w+') , php-fpm down can be written, outputint(3)

    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-fpmwhen 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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.