dongzhi4470
2015-11-27 10:35
浏览 76
已采纳

如何在php-fpm / nginx上停止php脚本执行?

Unfortunately calling php exit() on php-fpm/nginx configuration does not stop the script immediately while file handles might not be closed.

Some developers suggest calling fastcgi_finish_request() but also this does not stop the script.

Others suggest wrapping all code in a catch block:

<?php
    class SystemExit extends Exception {}
    try {
       /* PUT ALL THE CODE HERE */
    } catch (SystemExit $e) { /* do nothing */ }
?>

and throwing an exception where code stop is needed:

if (SOME_EXIT_CONDITION)
   throw new SystemExit(); // instead of exit()

This would mean editing all php files to include try/catch block and seems tedious to me.

Are there any other clean solutions?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题