在fastcgi_finish_request();声明后在我的 php 脚本中实施一些后处理后,我担心一些差异。
看起来 PHP 在 fastcgi_finish_request 之后没有执行所有脚本。
在日志文件中,我找不到关于这部分的通知,没有警告,没有错误或违规行为。
文档中是否有使用 fastcgi_finish_request 的限制或提示?
小智 5
调用 fastcgi_finish_request() 后任何显式或隐式输出刷新都将导致退出 PHP 脚本而没有任何警告或错误。换句话说,在调用 fastcgi_finish_request() 之后调用 flush() 的行为就像调用了 exit() 而不是 flush() 一样。
这是一些重现问题的代码:
function writestamp($case, $file){
file_put_contents($file, "". $case . ": " . time() . "" . PHP_EOL, FILE_APPEND);
}
// Flush buffers and stop output buffering
while (@ob_end_flush());
// Destroy session, otherwise request can't be finished
if(session_status() > 1) session_destroy();
$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);
Run Code Online (Sandbox Code Playgroud)
一个简单的解决方法是在调用ignore_user_abort(true)之前或之后fastcgi_finish_request调用:
ignore_user_abort(true);
fastcgi_finish_request();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2897 次 |
| 最近记录: |