Re: Does apache stop a script mid execution ?



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
.



Relevant Pages

  • Re: Difference between storing files on folder and in mysql db
    ... a separate instance of an image display script (and a separate ... connection if images were stored in the file system. ... know or care if the image is from a database or not. ... but the DB server does. ...
    (comp.lang.php)
  • Re: Does apache stop a script mid execution ?
    ... If the user calls a time consuming script and then stops or refreshes ... How does it relate to e.g. a script performing a large mysql query? ... 2.b) how the connection is set up. ... the server stops the script execution. ...
    (comp.lang.php)
  • Re: hitting the limits
    ... relatively straight forward MySql database. ... 10K visitors a month and an 80Mb database are nothing. ... heavily loaded server. ... But the connection will hang around until the garbage ...
    (comp.lang.php)
  • Re: VFP8 & MySQL
    ... > VFP functions like NVL to a MySQL one, definitely it made the switch very ... > About your connection problem, I have mine setup as default for 100 ... As for the server, we left it ... The server crashed and corrupted the database. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Shorewall and MySQL problem - solved
    ... Well, now the system accepts any connection besides mysql for ip,ip,ip ... It is a solution for mysql, but your server is now more at risk from ... firewall via poor programming practices. ...
    (comp.os.linux.networking)