Disabled forking/keep-alive code, firefox doesn't seem to like the way it waits for requests
--- a/functions.php Wed Apr 02 00:23:51 2008 -0400
+++ b/functions.php Wed Apr 02 01:36:53 2008 -0400
@@ -39,7 +39,7 @@
function status($msg)
{
$h = @fopen('php://stderr', 'w');
- $label = ( defined('HTTPD_WS_CHILD') ) ? 'Child ' . getmypid() : ' Greyhound ';
+ $label = ( defined('HTTPD_WS_CHILD') ) ? 'Child ' . substr(strval(getmypid()), -3) : 'Greyhound';
fwrite($h, "\x1B[32;1m[$label] \x1B[32;0m$msg\x1B[0m\n");
fclose($h);
}
--- a/greyhound.php Wed Apr 02 00:23:51 2008 -0400
+++ b/greyhound.php Wed Apr 02 01:36:53 2008 -0400
@@ -81,8 +81,7 @@
{
global $httpd;
status("Caught SIGTERM, cleaning up.");
- @socket_close($httpd->sock);
- exit();
+ exit(0);
}
status('initializing playlist');
@@ -133,7 +132,7 @@
}
}
$httpd->allow_dir_list = true;
- $httpd->allow_fork = ( $allow_fork ) ? true : false;
+ $httpd->allow_fork = false; // ( $allow_fork ) ? true : false;
$httpd->default_document = 'index';
status("Entering main server loop - ^C to interrupt, listening on port $port");
--- a/webserver.php Wed Apr 02 00:23:51 2008 -0400
+++ b/webserver.php Wed Apr 02 01:36:53 2008 -0400
@@ -164,6 +164,9 @@
// if this is a child process, we're finished - close up shop
if ( defined('HTTPD_WS_CHILD') && !$this->in_keepalive )
{
+ status('Exiting child process');
+ @socket_shutdown($remote);
+ @socket_close($remote);
exit(0);
}
@@ -201,14 +204,14 @@
else if ( $pid )
{
// we are the parent, continue listening
- $remote = false;
+ socket_close($remote);
continue;
}
else
{
// this is the child
define('HTTPD_WS_CHILD', 1);
- $this->sock = false;
+ socket_close($this->sock);
}
}
@@ -255,7 +258,7 @@
// enable keep-alive if requested
if ( isset($_SERVER['HTTP_CONNECTION']) && defined('HTTPD_WS_CHILD') )
{
- $this->in_keepalive = ( $_SERVER['HTTP_CONNECTION'] === 'keep-alive' );
+ $this->in_keepalive = ( strtolower($_SERVER['HTTP_CONNECTION']) === 'keep-alive' );
}
if ( isset($_SERVER['HTTP_AUTHORIZATION']) )
@@ -345,14 +348,16 @@
$this->send_standard_response($remote, $handler, $uri, $params);
- if ( !$this->in_keepalive )
+ if ( !$this->in_keepalive && defined('HTTPD_WS_CHILD') )
{
// if ( defined('HTTPD_WS_CHILD') )
// status('Closing connection');
+ @socket_shutdown($remote);
@socket_close($remote);
+ status('Exiting child process');
exit(0);
}
- else
+ else if ( defined('HTTPD_WS_CHILD') )
{
// if ( defined('HTTPD_WS_CHILD') )
// status('Continuing connection');
@@ -592,12 +597,16 @@
return true;
}
+ // $this->header('Transfer-encoding: chunked');
$this->header("Content-length: " . strlen($output));
$headers = implode("\r\n", $this->response_headers);
// write headers
$this->send_client_headers($socket, $this->response_code, $this->content_type, $headers);
+ // chunk output
+ // $output = dechex(strlen($output)) . "\r\n$output";
+
// write body
@socket_write($socket, $output);