Continue php script after connection close

后端 未结 4 1222
南旧
南旧 2020-12-30 19:09

I am trying to continue a PHP Script after the page/connection is closed.

Users will POLL the script in every 1 hour, I want to return some json output and want to c

4条回答
  •  别那么骄傲
    2020-12-30 19:27

    If you are using PHP-FPM, a cleaner and more versatile solution would be to simply execute fastcgi_finish_request();

    From PHP.net's documentation

    This function flushes all response data to the client and finishes the request. This allows for time consuming tasks to be performed without leaving the connection to the client open.

    This is how Symfony handles its onTerminate.

提交回复
热议问题