G
G
GM2mars2014-12-26 11:09:15
PHP
GM2mars, 2014-12-26 11:09:15

Correctly issuing a response to the client and continuing to execute PHP code?

The task arose, with an ajax request, give the client only the necessary data and continue the execution of the php code already in the background. Since the server is used by Apache, the following code was implemented:

ob_start();
echo json_encode($info);     //отдаем клиенту нужные данные
$contentLength=ob_get_length();
header('Connection: close');
header('Content-Length: ' . $contentLength);
ob_end_flush();
ob_flush();
flush();
//продолжаем выполнение

At first glance, everything works correctly, the server immediately responds to the client and then performs its task. But the whole problem is that when we make a second request to the server, we do not receive a response until the code from the previous request is executed.
I always thought that a separate php instance is created for each new request, or am I misunderstanding something?
How to implement this solution correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Burov, 2014-12-26
@GM2mars

Close php session session_write_close()
Better use php-fpm and fastcgi_finish_request

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question