Skip to content

Commit

Permalink
added some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelog committed Sep 11, 2011
1 parent 397fdcc commit 01fad4d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions fastagi.php
Expand Up @@ -36,18 +36,23 @@ function signalHandler($signal)
case SIGINT:
case SIGQUIT:
case SIGTERM:
// Do not run more than once.
if (!$running) {
break;
}
// Terminate main loop, do not accept any more calls.
$running = false;
// Wait for all ongoing calls to finish (actually kill them, then wait).
foreach ($children as $pid => $child) {
posix_kill($pid, SIGTERM);
pcntl_waitpid($pid, $status);
unset($children[$pid]);
}
// Remove pid file.
@unlink($pidFile);
break;
case SIGCHLD:
// A child exited normally (maybe..) so remove it from the current active list.
$pid = pcntl_waitpid(-1, $status);
unset($children[$pid]);
default:
Expand Down Expand Up @@ -104,6 +109,7 @@ function signalHandler($signal)
throw new \Exception("$pidFile already exists for pid: $pid");
}

// Save our pid.
$pid = posix_getpid();
if (file_put_contents($pidFile, $pid) === false) {
throw new \Exception("Could not write $pidFile");
Expand Down Expand Up @@ -140,6 +146,7 @@ function signalHandler($signal)
}
if ($result > 0) {
if (in_array($socket, $read)) {
// Accept new client.
$newSocket = stream_socket_accept($socket);
if ($newSocket !== false) {
$address = '';
Expand All @@ -148,6 +155,7 @@ function signalHandler($signal)
case 0:
try
{
// Launch PAGI application.
require_once $config['application']['bootstrap'];
$options = array();
$options['log4php.properties'] = $config['application']['log4php'];
Expand Down

0 comments on commit 01fad4d

Please sign in to comment.