php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48475 register_shutdown_function() does not execute after exit()
Submitted: 2009-06-05 02:41 UTC Modified: 2009-06-16 07:16 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: cagret at gmail dot com Assigned:
Status: Not a bug Package: Apache2 related
PHP Version: 5.2.9 OS: win32 only - Win XP SP3
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: cagret at gmail dot com
New email:
PHP Version: OS:

 

 [2009-06-05 02:41 UTC] cagret at gmail dot com
Description:
------------
Function registered with register_shutdown_function() is not executed after call to exit() on windows with latest php (php5 - failed, php4 - ok). On linux it works as expected (both php4 & php5 - ok).

I have tested many configurations, here is the summary:

* Win XP Sp3, Apache/2.2.11 php_mod, php versions: 5.2.9-2, 5.2.6, 5.2.8, 5.2.10RC1, 5.3.0RC2 (all versions FAILED)
* Win XP Sp3, Apache/1.3.34, php_mod, php 4.4.3-dev (OK)
* Linux, Lighttpd, cgi-fcgi, php 5.2.6 (OK)
* Linux, Apache/2.0.52 (CentOS), php_mod, php 4.3.9 (OK)

Reproduce code:
---------------
<?php

function shutdown()
{
	file_put_contents(dirname(__FILE__).'/shutdown.txt', time());
}
register_shutdown_function('shutdown');

exit();

?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-10 12:59 UTC] jani@php.net
Expected behaviour. exit() is supposed to exit immediately. Nothing is 
supposed to be run after you call exit.
 [2009-06-10 19:36 UTC] cagret at gmail dot com
I have installed php as fcgi under lighttpd on windows, and register_shutdown_function() is called after exit - all versions of php. The same under linux - I have tested many more configurations.

It seems that only under Apache on windows, register_shutdown_function() is not executed.

If this is expected behavior, than why it acts differently on different setups? Something is wrong.

In manual it is said, that after exit() called inside function registered by register_shutdown_function() nothing more will be executed, but here exit() is called outside of registered function. 

In comments on http://www.php.net/register_shutdown_function there are code examples that show that even after exit() that is not called inside registered shutdown function, the registered function IS executed - people think the other way about the expected behaviour.

And if this is expected behavior, it works as expected only on Windows Apache and php5 as php_mod.

I've made another test, Win + Apache + php5 as fcgi - and the file shutdown.txt is created after exit().

Summary:
I've tested over 10 configurations, Windows, Linux, Apache, Lightpd, php4, php5, php as cgi, php as mod - the only configuration that does not execute register_shutdown_function() after exit (that is called outside of registered function) is: Win + Apache + php5 as mod.

I don't think this is expected behavior, because it behaves as expected only on this configuration: Win+Apache+php5_as_mod.Please reconsider re-opening this issue.

Configurations summary:
Win+Apache+php5 as cgi - shutdown.txt is created
Win+Apache+php4 as mod - shutdown.txt is created
Win+Lighttpd+php5 as fcgi - shutdown.txt is created
Linux+Apache+php4 as mod - shutdown.txt is created
Linux+Lighttpd+php5 as fcgi - shutdown.txt is created
Win+Apache+php5 as mod - shutdown.txt IS NOT created.
 [2009-06-15 08:38 UTC] jani@php.net
And as it only happens with windows, it's a bug that needs to be fixed: 
exit() should exit there too.
 [2009-06-15 08:41 UTC] pajoye@php.net
I'm not sure it is windows specific. What's about Linux+Apache+php5 as mod?
 [2009-06-16 04:46 UTC] cagret at gmail dot com
I've just tested:
Linux + Apache2 + php 5.2.9 as mod: shutdown.txt IS created.
(http://testreg.netii.net/phpinfo.php)
 [2009-06-16 07:16 UTC] cagret at gmail dot com
Sorry, this is not a bug, I've found what was the problem, on Windows I had in php.ini directive auto_prepend_file which included auto_prepend.php and that file registered shutdown function debug_console() which had exit() inside!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC