Page 1 of 1

detaching the response

Posted: Sat Nov 14, 2009 12:34 am
by Woody222
is there any way in php to send back the response and finish the request response cycle but after that run more php code. The idea is I have the user input something and it is validated and then some heavy processing is done before a value is put into the database. What I want to do is after the validation send the response back to the user (exit or die normally) and then the processing be done on the server while the user isn't worrying about it at all. I hope I've got across the idea. I thought I could put the processy bit in a different php call and at the moment once the first one is done through ajax a second ajax request is sent for the processy bit, however I'm worried about relying on client side and would feel much better if once the first request was made I could be sure the whole operation would execute.

Woody

p.s. I dont know if this should be in code or design and theory, if it should be in code can a mod switch it please.

Re: detaching the response

Posted: Sat Nov 14, 2009 3:12 am
by alex.barylski

Re: detaching the response

Posted: Sat Nov 14, 2009 4:35 am
by VladSun

Re: detaching the response

Posted: Sat Nov 14, 2009 1:34 pm
by alex.barylski
Abort Flush Captain :P

Re: detaching the response

Posted: Sat Nov 14, 2009 2:06 pm
by josh
Even with the flushing functions sometimes the response still gets "chunked" by the web server or browser.

Re: detaching the response

Posted: Sat Nov 14, 2009 6:46 pm
by Christopher
How about using something like Gearman?

Re: detaching the response

Posted: Sun Nov 15, 2009 9:30 pm
by Woody222
ok I think I've figured a solution. Split the processy bit and the validation in to 2 php files. The first is validation files calls the second and then cuts the connection after 1 flush. The second file uses the abort setting then flushs ok back to the first page. To the user they see the first page finish and be told the validation is ok while the process can process unknown to the user.

any one is any problems with this?

Re: detaching the response

Posted: Sun Nov 15, 2009 9:54 pm
by josh
You could do

Code: Select all

 
exec( '/path/to/php myTask.php &' );
 
which would spawn a background task

You could also use the 'nice' command to set the processing priority. This would restrict you in terms of compatible hosting.

Re: detaching the response

Posted: Tue Nov 17, 2009 3:47 am
by Jenk