Re: does php require a client is present to execute?



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@xxxxxxxxxxxxx
==================

.



Relevant Pages

  • Re: Excecute PHP script in SSL protected dir / sched. task on win 2k3 server
    ... >> I want to execute a PHP script that is in a SSL secured directory through ... > This should be able to be added to the schedule with help of a small batch ...
    (alt.php)
  • Execute Process Task : Help!!!
    ... I'm trying to execute a script on our web server, a PHP script, using ... "Execute Process Task" task in DTS designer. ...
    (microsoft.public.sqlserver.dts)
  • PHP scripting errror -Why?
    ... Does anyone see what I am doing wrong with this simple script? ... >> So the PHP script IS running, and I am receiving an email... ... > be the HTML back to the browser. ... that the headercommand redirects the user back to the page they were ...
    (alt.php)
  • Re: [PHP] Re: how to detect type of image
    ... you detect if a script is HTML or PHP? ... to execute a file that starts with 'GIF89a' as if it were a binary ... manage to trick your PHP script into putting it somewhere that it will ... Every extra barrier you layer in there will slim down the number of ...
    (php.general)
  • Re: [PHP] pdo-oracle + nls_lang environment variable...
    ... I'm using pdo-oci on php-5.2.2 against an oracle-10g server, ... I make a simple php script that makes a select from a table. ... user running the apache daemon, I modified the apache init script to export ...
    (php.general)