detaching the response
Moderator: General Moderators
detaching the response
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.
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.
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: detaching the response
together with
http://www.php.net/manual/en/function.flush.php
http://www.php.net/manual/en/function.flush.php
There are 10 types of people in this world, those who understand binary and those who don't
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: detaching the response
Abort Flush Captain 
Re: detaching the response
Even with the flushing functions sometimes the response still gets "chunked" by the web server or browser.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: detaching the response
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?
any one is any problems with this?
Re: detaching the response
You could do
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.
Code: Select all
exec( '/path/to/php myTask.php &' );
You could also use the 'nice' command to set the processing priority. This would restrict you in terms of compatible hosting.