fastcgi_finish_request

(PHP 5 >= 5.3.3, PHP 7, PHP 8)

fastcgi_finish_requestСбрасывает все запрошенные данные клиенту

Описание

fastcgi_finish_request(): bool

Эта функция сбрасывает все запрошенные данные клиенту и завершает обработку запроса. Это позволяет выполнять длительные задачи без поддержания связи с клиентом.

Список параметров

У этой функции нет параметров.

Возвращаемые значения

Возвращает true в случае успешного завершения или false в случае возникновения ошибки.

add a note add a note

User Contributed Notes 2 notes

up
64
tuxrampage
7 years ago
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.
up
0
Patrick Allaert
2 years ago
This is very poor man's approach to async execution.

Better relying on message queues to process something asynchronously.
To Top