0

I am running some php installation script from a browser and it's been running for a quite long time. Is there a way to check if it is still running on a server or timed out already? The browser is still showing loading spinner, but it is not a reliable progress indicator I suppose.

(Apache webserver under Linux)

2 Answers 2

0

mod_status/Server-Status should do the trick.

<Location /server-status>
    SetHandler server-status
</Location>

Uncomment the above lines in your httpd.conf,

Then hit yoursite-or-ipaddress/server-status.

You should see a list of all the requests apache is working on, as well as that basic status of each one.

Scoreboard Key:
"_" Waiting for Connection, "S" Starting up, "R" Reading Request,
"W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
"C" Closing connection, "L" Logging, "G" Gracefully finishing,
"I" Idle cleanup of worker, "." Open slot with no current process


Srv PID Acc M   CPU     SS  Req Conn    Child   Slot    Client  VHost   Request
113-812 -   0/0/496 .   6.21    3025    2589    0.0 0.00    32.97   127.127.127.127 green.org   GET /images/Image/inside_repeat.png HTTP/1.1
2
  • Thanks, but that requires apache restart, isn't it? So I need to be prepared upfront.
    – serg
    Apr 28, 2010 at 0:14
  • pretty sure it needs just a reload, which should keep your running script going.
    – grufftech
    Apr 28, 2010 at 15:27
0

If I'm not mistaken, the browser will run until the script is finished either by timeout, by memory exhaustion, or any other method that would kill the script on the server. I have some data processing scripts that run for 30 minutes or so. There nothing that I know of that would cause the browser state to freeze thinking the script is still loading after it has timed out on the server.

If you still want to monitor the script, the only way that I know of doing this would be to execute the script in the background, and check to see if the process is still running every few seconds. Since php isn't asynchronous like Java, it takes some hacking to get a function like this to work.

You would want to execute the script in the background:

exec('/path/to/php -f /path/to/script.php > /dev/null 2>&1 & echo $!',$op);
$pid = (int)$op[0]; 

Then, you can use a function like this to check if a process is still running.

   function isRunning($pid) {
        exec("ps $pid", $ProcessState);
        return(count($ProcessState) >= 2);
    }

Then you would use

while(isRunning($pid)) {
echo 'Still running...';
sleep(10);
//or something like this
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .