php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78396 Second file_put_contents in Shutdown hangs script
Submitted: 2019-08-10 13:33 UTC Modified: 2019-08-10 14:12 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: herbert at groot dot jebbink dot nl Assigned: nikic (profile)
Status: Closed Package: *General Issues
PHP Version: 7.4.0beta2 OS: Debian Stretch (inside ChromeOS)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
31 - 27 = ?
Subscribe to this entry?

 
 [2019-08-10 13:33 UTC] herbert at groot dot jebbink dot nl
Description:
------------
The second file_put_contents to the same file inside the Shutdown function does never happen, the script hangs.

When removing the 'LOCK_EX' option it works.

The setup is a own build inside Debian Stretch inside ChromeOS (with crouton), Apache is used from the Stretch distribution.

./configure --with-apxs2=/usr/bin/apxs2 --with-mysql-sock=/run/mysqld/mysqld.sock --enable-mbstring --enable-exif --enable-ftp --with-zip --enable-soap --with-mysqli --with-pdo-mysql --with-curl --with-openssl --with-zlib --with-bz2 --enable-gd --with-webp --with-jpeg --with-xpm --with-freetype --with-tidy --with-xsl --with-sodium --enable-shmop --with-mm --with-pspell --with-pear

The content of php.ini is

zend_extension=opcache.so
max_execution_time=2
memory_limit=2048M
display_errors=on
error_reporting=E_ALL




Test script:
---------------
<?php
 
  register_shutdown_function ('shutdown');
  file_put_contents ('/home/me/data/test.txt', "main 1 \n", FILE_APPEND | LOCK_EX);
  file_put_contents ('/home/me/data/test.txt', "main 2 \n", FILE_APPEND | LOCK_EX);
  a: goto a;
  
  function shutdown () {
    $error = error_get_last();
    if ( ! is_null($error) ) {
      file_put_contents ('/home/me/data/test.txt', "shutdown 1 \n", FILE_APPEND | LOCK_EX);
      file_put_contents ('/home/me/data/test.txt', "shutdown 2 \n", FILE_APPEND | LOCK_EX);
    }
    
    exit;
    
  }

?>

Expected result:
----------------
main 1 
main 2 
shutdown 1 
shutdown 2


Actual result:
--------------
main 1 
main 2 
shutdown 1 


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-08-10 14:08 UTC] sjon@php.net
-Status: Open +Status: Verified
 [2019-08-10 14:08 UTC] sjon@php.net
without looking into this further, this seems to fail since alpha3

https://3v4l.org/MM3fT
 [2019-08-10 14:10 UTC] herbert at groot dot jebbink dot nl
-Status: Verified +Status: Open
 [2019-08-10 14:10 UTC] herbert at groot dot jebbink dot nl
The fact that the shutdown function in my test script was activated by a max-execution-time exception is not relevant.

Below test script has the same problem.

<?php
 
  register_shutdown_function ('shutdown');

  file_put_contents ('/tmp/test.txt', '1', FILE_APPEND | LOCK_EX);
  file_put_contents ('/tmp/test.txt', '2', FILE_APPEND | LOCK_EX);

  function shutdown () {
    file_put_contents ('/tmp/test.txt', '3', FILE_APPEND | LOCK_EX);
    file_put_contents ('/tmp/test.txt', '4', FILE_APPEND | LOCK_EX);
  }

?>
 [2019-08-10 14:12 UTC] nikic@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: nikic
 [2019-08-10 14:12 UTC] nikic@php.net
Probably because explicit resource destructors are not called during resource shutdown, but this accidentally also disables them during shutdown functions.
 [2019-08-12 08:45 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a18ad194c470156f03a5ea2cb9174cc26bc5e618
Log: Fixed bug #78396
 [2019-08-12 08:45 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 22:01:26 2024 UTC