Re: Long running db queries and the "STOP" button

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thomas.Seiler@xxxxxxxxxxxx wrote:
Hi Jochem, Thanks for replying

I just had the idea (never tried it myself) that you could possibly
fork the request process and let the child process perform the query


It makes perfectly sense to us, but it seems it is only possible to fork
(pcntl_fork) with php running as CGI :(

oops missed that bit in the manual... still ...

if you are using apache then virtual() might offer a solution? (just guessing)

otherwise you might look into writing a little deamon (i.e. a webservice
that only your pages anbd/or scripts can access) which handles running the
queries can be polled as to the status of a query and its result (if finished) ..
such a deamon would be CLI based and could use process forking to handle multiple
requests to run long queries....

rather than use the <img src="monitorscript.php"> trick you might want to look into
'AJAX' on the client side (to do the polling, start the query, etc) in order to
have more control/information on that end.


From php.net:
<snip>
arnold at helderhosting dot nl
13-Feb-2005 10:12 It is not possible to use the function 'pcntl_fork' when PHP is used as
Apache module. You can only use pcntl_fork in CGI mode or from
command-line.

Using this function will result in: 'Fatal error: Call to undefined
function: pcntl_fork()'
<snip>

This somehow makes sense, because one would fork the entire apache
process, Including all the signal handlers, open file handles for log-files and
so on...

Furthermore fork is only supported on linux/*nix but not in the windows
world, and it has to be enabled at configure time.

We have so far tried to use javascript to detect when a windows is
closed and send a second HTTP request to kill the database thread. This
however does not work reliably, because javascript has no event for the
"Stop" button of the browser :(

a daily annoyance. just like its impossible to trap when the window is actually
closed (as opposed to the document merely unloading)


The next idea is to include a <img src="monitorscript.php"> in output
generated by the query script. This should open a second HTTP connection
to the monitor script on most recent browsers. In this script we can
check connection_aborted() and sleep(1) in a while loop without sending
any output. If the connection was aborted, we can kill the corresponding
db thread.
The remaining problem with that solution is that we also have to detect
when the db query script has terminated and then exit the monitor
script. Otherwise the browser keeps loading that monitorscript and never
finishes.
This solution has two drawbacks, it work over a http proxy (these tend
to finish queries in order to cache the content) and it works only when
the browser is doing several queries in parallel.

Cheers,
Thomas

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux