does php require a client is present to execute?
does php require a client is present to execute?
am 07.01.2008 06:09:58 von fischp
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
Re: does php require a client is present to execute?
am 07.01.2008 06:23:20 von Steve
"Paul Fisch" wrote in message
news:6ed03236-c73c-4b9b-8732-da098aa1be8b@s8g2000prg.googleg roups.com...
> 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?
in most cases, yet. however, that can be controlled by the server.
> Also could this work using
> ajax if a javascript script then triggers a php script?
yes.
Re: does php require a client is present to execute?
am 07.01.2008 06:32:25 von fischp
On Jan 6, 11:23 pm, "Steve" wrote:
> "Paul Fisch" wrote in message
>
> news:6ed03236-c73c-4b9b-8732-da098aa1be8b@s8g2000prg.googleg roups.com...
>
> > 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?
>
> in most cases, yet. however, that can be controlled by the server.
>
> > Also could this work using
> > ajax if a javascript script then triggers a php script?
>
> yes.
Explain controlled by the server.
Will it automatically be set to execute till completion or do I need
to modify any php settings?
Re: does php require a client is present to execute?
am 07.01.2008 07:32:51 von Steve
"Paul Fisch" wrote in message
news:7d725e08-d14d-454f-892f-9ad9900616a4@h11g2000prf.google groups.com...
> On Jan 6, 11:23 pm, "Steve" wrote:
>> "Paul Fisch" wrote in message
>>
>> news:6ed03236-c73c-4b9b-8732-da098aa1be8b@s8g2000prg.googleg roups.com...
>>
>> > 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?
>>
>> in most cases, yet. however, that can be controlled by the server.
>>
>> > Also could this work using
>> > ajax if a javascript script then triggers a php script?
>>
>> yes.
>
> Explain controlled by the server.
>
> Will it automatically be set to execute till completion or do I need
> to modify any php settings?
it really depends on your setup...whether or not php is being run as a
module or as a cgi, what webserver you're using - it's the webserver
software that can control this.
Re: does php require a client is present to execute?
am 07.01.2008 08:33:37 von fischp
On Jan 7, 12:32 am, "Steve" wrote:
> "Paul Fisch" wrote in message
>
> news:7d725e08-d14d-454f-892f-9ad9900616a4@h11g2000prf.google groups.com...
>
>
>
> > On Jan 6, 11:23 pm, "Steve" wrote:
> >> "Paul Fisch" wrote in message
>
> >>news:6ed03236-c73c-4b9b-8732-da098aa1be8b@s8g2000prg.googl egroups.com...
>
> >> > 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?
>
> >> in most cases, yet. however, that can be controlled by the server.
>
> >> > Also could this work using
> >> > ajax if a javascript script then triggers a php script?
>
> >> yes.
>
> > Explain controlled by the server.
>
> > Will it automatically be set to execute till completion or do I need
> > to modify any php settings?
>
> it really depends on your setup...whether or not php is being run as a
> module or as a cgi, what webserver you're using - it's the webserver
> software that can control this.
Do you know where I could go or what terms I should search to find out
more about this.
Re: does php require a client is present to execute?
am 07.01.2008 09:14:34 von DFS
On Sun, 6 Jan 2008 23:33:37 -0800 (PST), Paul Fisch
wrote:
>> it really depends on your setup...whether or not php is being run as a
>> module or as a cgi, what webserver you're using - it's the webserver
>> software that can control this.
>
>Do you know where I could go or what terms I should search to find out
>more about this.
I'm also interested in how to handle long-running PHP processes.
Not sure if this is true, but here goes anyway:
- the server and/or the browser usually time out after 30 seconds
(HTTP protocol?), so the PHP script must regularly send some data to
keep the pipes open
- if the browser is closed, the PHP process will still run unless you
put some code that checks for this, and aborts if the connection was
closed
- generally speaking, LAMP is not a good choice for long-running
tasks. You might want to use other tools for this
Re: does php require a client is present to execute?
am 07.01.2008 09:19:34 von fischp
On Jan 7, 2:14 am, Gilles Ganault wrote:
> On Sun, 6 Jan 2008 23:33:37 -0800 (PST), Paul Fisch
> wrote:
>
> >> it really depends on your setup...whether or not php is being run as a
> >> module or as a cgi, what webserver you're using - it's the webserver
> >> software that can control this.
>
> >Do you know where I could go or what terms I should search to find out
> >more about this.
>
> I'm also interested in how to handle long-running PHP processes.
>
> Not sure if this is true, but here goes anyway:
> - the server and/or the browser usually time out after 30 seconds
> (HTTP protocol?), so the PHP script must regularly send some data to
> keep the pipes open
> - if the browser is closed, the PHP process will still run unless you
> put some code that checks for this, and aborts if the connection was
> closed
> - generally speaking, LAMP is not a good choice for long-running
> tasks. You might want to use other tools for this
Using the command set_time_limit(some #) can extend the timeout limit
to whatever you want.
Why isn't LAMP a good choice for long-running tasks?
Re: does php require a client is present to execute?
am 07.01.2008 09:34:20 von DFS
On Mon, 7 Jan 2008 00:19:34 -0800 (PST), Paul Fisch
wrote:
>Using the command set_time_limit(some #) can extend the timeout limit
>to whatever you want.
I could be wrong, but it doesn't matter what is set in the PHP
scripts: If the server and/or the browser time out after X seconds,
the script will fail unless it keeps pumping data out to keep the
connection open.
>Why isn't LAMP a good choice for long-running tasks?
Because it's meant for fast query-reply, not to keep the connection
open for 15 minutes. Why does this have to be written as a web
application, and what does it really do? Heavy data mining, or
computation?
Re: does php require a client is present to execute?
am 07.01.2008 10:01:18 von fischp
On Jan 7, 2:34 am, Gilles Ganault wrote:
> On Mon, 7 Jan 2008 00:19:34 -0800 (PST), Paul Fisch
> wrote:
>
> >Using the command set_time_limit(some #) can extend the timeout limit
> >to whatever you want.
>
> I could be wrong, but it doesn't matter what is set in the PHP
> scripts: If the server and/or the browser time out after X seconds,
> the script will fail unless it keeps pumping data out to keep the
> connection open.
>
> >Why isn't LAMP a good choice for long-running tasks?
>
> Because it's meant for fast query-reply, not to keep the connection
> open for 15 minutes. Why does this have to be written as a web
> application, and what does it really do? Heavy data mining, or
> computation?
Computation and lots of api queries. I plan to use ajax to let it run
in the background and load the data into sql tables and to deliver the
data when its ready.
Re: does php require a client is present to execute?
am 07.01.2008 12:06:13 von DFS
On Mon, 7 Jan 2008 01:01:18 -0800 (PST), Paul Fisch
wrote:
>Computation and lots of api queries. I plan to use ajax to let it run
>in the background and load the data into sql tables and to deliver the
>data when its ready.
I'll be interested in what the experts have to say about this, as I'd
also like to run lengthy processes, and would rather write this as a
web app to reduce deployment issues.
Re: does php require a client is present to execute?
am 07.01.2008 12:56:27 von Jerry Stuckle
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
==================
Re: does php require a client is present to execute?
am 07.01.2008 13:24:05 von luiheidsgoeroe
On Mon, 07 Jan 2008 06:09:58 +0100, 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?
That's configurable, look at
http://nl2.php.net/manual/en/features.connection-handling.ph p and
ignore_user_abort().
--
Rik Wasmus
Re: does php require a client is present to execute?
am 07.01.2008 13:26:56 von colin.mckinnon
On 7 Jan, 11:56, Jerry Stuckle wrote:
> 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.
>
> --
Nobody seems to have mentioned that:
1) there is a whole chapter in the manual on this :
http://www.php.net/manual/en/features.connection-handling.ph p
2) you should also set ignore_user_abort(true); as detailled in the
above.
The reason its a bad idea to do this via the webserver is that the
webserver itself may impose additional constraints in how long a
process runs for, and what resources it accesses. Its also difficult
to manage the resource intensive script independently of the
webserver. A better solution is to run it in the CLI PHP. Try googling
for PHP "long running process" for lots of information.
C.