我知道Nginx与PHP-FPM进程无关,但是我更希望如果用户中止而导致PHP-FPM进程死亡,那么它就不会继续做不必要的事情或浪费资源。对于PHP-FPM / Nginx,trigger_error无论用户中止如何都会发生:
<?php
sleep(30);
trigger_error('Still happened?');
?>
Run Code Online (Sandbox Code Playgroud)
用户如何中止PHP-FPM?(如果可能的话)
我似乎无法使用connection_aborted函数来使用nginx.我以前测试的代码如下:
<?php
ignore_user_abort(true);
ob_implicit_flush();
$i = 0;
while (!connection_aborted()) {
echo $i;
$i++;
sleep(1);
}
file_put_contents('test',$i);
Run Code Online (Sandbox Code Playgroud)
在Apache中,它可以正常工作,虽然它有点延迟.即,当我在"3"时按下浏览器上的停止按钮时,"测试"文件显示"8".这是一个可接受的余量,但在nginx上,它似乎没有向'test'文件输出任何内容.