By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,199 Members | 1,458 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,199 IT Pros & Developers. It's quick & easy.

Does apache stop a script mid execution ?

P: n/a

Hi everybody,

I have a quick and probably dumb question, keep in mind I just
dumped my old love FastCGI + Perl for it's younger hotter friend PHP5.

If the user calls a time consuming script and then stops or refreshes
the browser before the script had time to finish will Apache kill the
script mid execution or will it let it finish ?

I ask this stupid question because this seems to be happening in one
of my sites.

If this is true, is there any way to tell apache to finish what it
was doing ?

Cheers,
GA

--
Guillermo Antonio Amaral Bastidas (gamaral)
Free/Libre/Open-Source Software Developer : http://www.guillermoamaral.com/
Jul 22 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Guillermo Antonio Amaral Bastidas wrote:
>
Hi everybody,

I have a quick and probably dumb question, keep in mind I just
dumped my old love FastCGI + Perl for it's younger hotter friend PHP5.

If the user calls a time consuming script and then stops or refreshes
the browser before the script had time to finish will Apache kill the
script mid execution or will it let it finish ?

I ask this stupid question because this seems to be happening in one
of my sites.

If this is true, is there any way to tell apache to finish what it
was doing ?
Yes, it DOES stop the execution.
That is usually the desired behaviour, since you dont want to spend all the
valuable cpu ressource to produce a result noone is ever going to see
anyway because the client has gone away.
However you can change this behaviour: take a look at the ignore_user_abort
function

arkascha
Jul 22 '08 #2

P: n/a
arkascha wrote:
Guillermo Antonio Amaral Bastidas wrote:
> Hi everybody,

I have a quick and probably dumb question, keep in mind I just
dumped my old love FastCGI + Perl for it's younger hotter friend PHP5.

If the user calls a time consuming script and then stops or refreshes
the browser before the script had time to finish will Apache kill the
script mid execution or will it let it finish ?

I ask this stupid question because this seems to be happening in one
of my sites.

If this is true, is there any way to tell apache to finish what it
was doing ?

Yes, it DOES stop the execution.
That is usually the desired behaviour, since you dont want to spend all the
valuable cpu ressource to produce a result noone is ever going to see
anyway because the client has gone away.
However you can change this behaviour: take a look at the ignore_user_abort
function
that is interesting and worth knowing.

How does it relate to e.g. a script performing a large mysql query?
arkascha
Jul 22 '08 #3

P: n/a
The Natural Philosopher wrote:
arkascha wrote:
>Guillermo Antonio Amaral Bastidas wrote:
>> Hi everybody,

I have a quick and probably dumb question, keep in mind I just
dumped my old love FastCGI + Perl for it's younger hotter friend PHP5.

If the user calls a time consuming script and then stops or refreshes
the browser before the script had time to finish will Apache kill the
script mid execution or will it let it finish ?

I ask this stupid question because this seems to be happening in one
of my sites.

If this is true, is there any way to tell apache to finish what it
was doing ?

Yes, it DOES stop the execution.
That is usually the desired behaviour, since you dont want to spend all
the valuable cpu ressource to produce a result noone is ever going to see
anyway because the client has gone away.
However you can change this behaviour: take a look at the
ignore_user_abort function

that is interesting and worth knowing.
How does it relate to e.g. a script performing a large mysql query?
Hm, interesting question...

I'd say "depends, actually", since it depends, actually :-)

It should depend on two things:
1.) the way you use php in your environment
2.) the way the client is implemented in the php mysql extension and
2.b) how the connection is set up.

In case you use php as cgi-executable the whole process is stopped in case
the server stops the script execution. This means the client (the process)
disconnects from the mysql server which drops the query, unless there is
some hidden feature in mysql you can use to prevent this (I don't know
about that).

Opposed to that if you use php as an apache module (more common nowadays)
the process is usually _not_ terminated but serves subsequent requests to
the http server (unless its maximum request or duration limits have been
reached which is unlikely). In this case it depends on how the mysql
connection is held. I'd say (note: I dont know) that in case of a "normal"
connection the script abortion triggers the connection to be dropped, this
the query to be dropped by the mysql server, just as if you use a command
line client and disconnect during a query (CTRL-C). If, however, you use a
persistent connection (mysql_pconnect() or something close to that) I'd
say that the connection is _not_ dropped, and I am not sure if there is any
mechanism to notify the server that the query is meant to be cancelled. It
should be possible however, since you can do that when using the command
line client...
Have a try and tell us...

arkascha
Jul 22 '08 #4

P: n/a
arkascha wrote:
The Natural Philosopher wrote:
>arkascha wrote:
>>Guillermo Antonio Amaral Bastidas wrote:

Hi everybody,

I have a quick and probably dumb question, keep in mind I just
dumped my old love FastCGI + Perl for it's younger hotter friend PHP5.

If the user calls a time consuming script and then stops or refreshes
the browser before the script had time to finish will Apache kill the
script mid execution or will it let it finish ?

I ask this stupid question because this seems to be happening in one
of my sites.

If this is true, is there any way to tell apache to finish what it
was doing ?
Yes, it DOES stop the execution.
That is usually the desired behaviour, since you dont want to spend all
the valuable cpu ressource to produce a result noone is ever going to see
anyway because the client has gone away.
However you can change this behaviour: take a look at the
ignore_user_abort function
that is interesting and worth knowing.
How does it relate to e.g. a script performing a large mysql query?

Hm, interesting question...

I'd say "depends, actually", since it depends, actually :-)

It should depend on two things:
1.) the way you use php in your environment
2.) the way the client is implemented in the php mysql extension and
2.b) how the connection is set up.

In case you use php as cgi-executable the whole process is stopped in case
the server stops the script execution. This means the client (the process)
disconnects from the mysql server which drops the query, unless there is
some hidden feature in mysql you can use to prevent this (I don't know
about that).

Opposed to that if you use php as an apache module (more common nowadays)
the process is usually _not_ terminated but serves subsequent requests to
the http server (unless its maximum request or duration limits have been
reached which is unlikely). In this case it depends on how the mysql
connection is held. I'd say (note: I dont know) that in case of a "normal"
connection the script abortion triggers the connection to be dropped, this
the query to be dropped by the mysql server, just as if you use a command
line client and disconnect during a query (CTRL-C).
That seems to be the way it would work, that the calling library would
exit, and close the socket to the server..would that abort the server
activity/process though?
If, however, you use a
persistent connection (mysql_pconnect() or something close to that) I'd
say that the connection is _not_ dropped, and I am not sure if there is any
mechanism to notify the server that the query is meant to be cancelled. It
should be possible however, since you can do that when using the command
line client...
Have a try and tell us...
No sure how I'd even try.

>
arkascha
Jul 22 '08 #5

P: n/a
arkascha <no_spam@no_spam.orgwrites:
Guillermo Antonio Amaral Bastidas wrote:
> I have a quick and probably dumb question, keep in mind I just
dumped my old love FastCGI + Perl for it's younger hotter friend PHP5.

If the user calls a time consuming script and then stops or refreshes
the browser before the script had time to finish will Apache kill the
script mid execution or will it let it finish ?

I ask this stupid question because this seems to be happening in one
of my sites.

If this is true, is there any way to tell apache to finish what it
was doing ?

Yes, it DOES stop the execution.
That is usually the desired behaviour, since you dont want to spend all the
valuable cpu ressource to produce a result noone is ever going to see
anyway because the client has gone away.
However you can change this behaviour: take a look at the ignore_user_abort
function
Thanks for the heads up! :-)

--
Guillermo Antonio Amaral Bastidas (gamaral)
Free/Libre/Open-Source Software Developer : http://www.guillermoamaral.com/
KDE Banana : http://www.kde.org/
Jul 23 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.