|
Posted by Jerry Stuckle on 01/07/08 11:56
Paul Fisch wrote:
> This might not be the correct place for this question, if not if
> someone could point me in the right direction that would be good.
>
> Ok, let's say you have an html document that calls a php script. Now
> the php script doesn't even necessarily have to output any information
> to the client, but lets just say that all it does is some very complex
> sql stuff involving large tables that takes as long as 10 minutes to
> execute. The script includes set_time_limit(1500). Now if someone
> views the html page for 10-15 seconds and then closes the page will
> the php script continue and execute until completion even though the
> client has long since closed the page? Also could this work using
> ajax if a javascript script then triggers a php script?
>
> Thanks,
> Paul Fisch
>
Paul,
First thing - you have two different timeouts to worry about. The first
one is the PHP script itself, which you can change with set_time_limit()
(if the server allows it). The other limit is the browser, which you
can't change in PHP.
Now, you can start a batch script to execute your long-running code.
But normally it will execute synchronously - that is, your web server
script will wait for the batch script to finish. During this time your
existing script won't complete its execution, so the user won't be able
to continue (and the browser may time out).
You can start the batch script as a background task. As a background
task, the script will not be able to display any output, nor will it be
able to return results to the user (because the web server script has
moved on). But the web server script will complete processing and
return to the user.
Of course, another possibility is to queue up the work to be done (i.e.
in a database) and run a cron job on a regular basis to check the queue
and process anything waiting. This works great if there is no need to
process the data immediately.
Hope this gives you some ideas.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|