My script is called by server. From server I'll receive ID_OF_MESSAGE
and TEXT_OF_MESSAGE
.
In my script I'll handle incoming text and generate response with params: ANSWER_TO_ID
and RESPONSE_MESSAGE
.
The problem is that I'm sending response to incomming "ID_OF_MESSAGE"
, but server which send me message to handle will set his message as delivered to me (It means I can send him response to that ID), after receiving http response 200.
One of solution is to save message to database and make some cron which will be running each minute, but I need to generate response message immediately.
Is there some solution how to send to server http response 200 and than continue executing php script?
Thank you a lot
Yes. You can do this:
I asked this question to Rasmus Lerdorf in April 2012, citing these articles:
I suggested the development of a new PHP built-in function to notify the platform that no further output (on stdout?) will be generated (such a function might take care of closing the connection). Rasmus Lerdorf responded:
I can see his point, and support his opinion for some applications/ loading scenarios! However, under some other scenarios, the solutions from vcampitelli et al, are good ones.
For some obscure reasons, none of these solutions work when using MAMP PRO (Apache, MySQL, PHP).
There is another approach and its worthwhile considering if you don't want to tamper with the response headers. If you start a thread on another process the called function wont wait for its response and will return to the browser with a finalized http code. You will need to configure pthread.
Once we execute $continue_processing->start() PHP wont wait for the return result of this thread and therefore as far as rest_endpoint is considered. It is done.
Some links to help with pthreads
Good luck.
in case of php file_get_contents use, connection close is not enough. php still wait for eof witch send by server.
my solution is to read 'Content-Length:'
here is sample :
response.php:
Note the "\n" in response to close line, if not the fget read while wait eof.
read.php :
As you can see this script dosent wait about eof if content length is reach.
hope it will help
I have something that can compressed and send the response and let other php code to execute.