fastcgi_finish_request

(PHP 5 >= 5.3.3, PHP 7)

fastcgi_finish_request冲刷(flush)所有响应的数据给客户端

说明

boolean fastcgi_finish_request ( void )

此函数冲刷(flush)所有响应的数据给客户端并结束请求。 这使得客户端结束连接后,需要大量时间运行的任务能够继续运行。

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

User Contributed Notes

tuxrampage 04-Aug-2016 06:29
There are some pitfalls  you should be aware of when using this function.

The script will still occupy a FPM process after fastcgi_finish_request(). So using it excessively for long running tasks may occupy all your FPM threads up to pm.max_children. This will lead to gateway errors on the webserver.

Another important thing is session handling. Sessions are locked as long as they're active (see the documentation for session_write_close()). This means subsequent requests will block until the session is closed.

You should therefore call session_write_close() as soon as possible (even before fastcgi_finish_request()) to allow subsequent requests and a good user experience.

This also applies for all other locking techniques as flock or database locks for example. As long as a lock is active subsequent requests might bock.