webserver.php
changeset 16 23d4cf2f183b
parent 15 2adca0f363fd
child 17 66c3eb4cdc4c
--- 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);