Bug #68772 [NEW]: calling flush() after fastcgi_finish_request() exits PHP without errors or warn
| From: | rikurr at gmail dot com | Date: | Fri, 09 Jan 2015 01:32:43 +0000 |
| Subject: | Bug #68772 [NEW]: calling flush() after fastcgi_finish_request() exits PHP without errors or warn | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-189818@lists.php.net to get a copy of this message | ||
From: rikurr at gmail dot com
Operating system: Linux
PHP version: 5.4.36
Package: Output Control
Bug Type: Bug
Bug description:calling flush() after fastcgi_finish_request() exits PHP without errors or warn
Description:
------------
At least explicit flushing after calling fastcgi_finish_request() will
exit PHP without any errors or warnings.
I found this behavior while writing a code that:
1) calls fastcgi_finish_request() and based on parameters either
1.a) continues processing in the background (asynchronous)
1.b) streams the processsing logs to the screen (synchronous)
2) has a generic logging method that both echoes+flushes(streaming) and
writes the logs to a file.
As a workaround I will have have to check the parameter condition during
logging to not to flush if fastcgi_finish_request() was called.
Related:
http://stackoverflow.com/questions/14191947/php-fpm-fastcgi-finish-request-reliable/27847878#27847878
Test script:
---------------
<?php
function writestamp($case, $file){
file_put_contents($file, "". $case . ": " . time() . "" . PHP_EOL,
FILE_APPEND);
}
$file = tempnam(sys_get_temp_dir(), 'flushbug_');
echo 'Writing 4 timestamps to: '.$file;
// this one gets called
writestamp('1', $file);
// and this
register_shutdown_function('writestamp', '4', $file);
// finish the request
fastcgi_finish_request();
// as does this
writestamp('2', $file);
// but this one does NOT - calling flush() after
fastcgi_finish_request() exits PHP without errors or warnings
flush();
writestamp('3', $file);
Expected result:
----------------
PHP should continue processing the script if I flush() output to the
client after calling fastcgi_finish_request() and output 4 lines to the
temporary file:
1: 1420766961
2: 1420766961
3: 1420766961
4: 1420766961
Actual result:
--------------
PHP exits the process without, at least to my knowledge, errors or
warnings and only outputs 3 lines to the temporary file:
root@afa63474201a:/# cat /tmp/flushbug_XCsRsu
1: 1420766961
2: 1420766961
4: 1420766961
--
Edit bug report at https://bugs.php.net/bug.php?id=68772&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68772&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68772&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68772&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=68772&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=68772&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=68772&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=68772&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=68772&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=68772&r=support
Expected behavior: https://bugs.php.net/fix.php?id=68772&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=68772&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=68772&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=68772&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68772&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=68772&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=68772&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=68772&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68772&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=68772&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=68772&r=mysqlcfg