equal
deleted
inserted
replaced
162 while ( true ) |
162 while ( true ) |
163 { |
163 { |
164 // if this is a child process, we're finished - close up shop |
164 // if this is a child process, we're finished - close up shop |
165 if ( defined('HTTPD_WS_CHILD') && !$this->in_keepalive ) |
165 if ( defined('HTTPD_WS_CHILD') && !$this->in_keepalive ) |
166 { |
166 { |
|
167 status('Exiting child process'); |
|
168 @socket_shutdown($remote); |
|
169 @socket_close($remote); |
167 exit(0); |
170 exit(0); |
168 } |
171 } |
169 |
172 |
170 // wait for connection... |
173 // wait for connection... |
171 // trick from http://us.php.net/manual/en/function.socket-accept.php |
174 // trick from http://us.php.net/manual/en/function.socket-accept.php |
199 // do nothing; continue responding to request in single-threaded mode |
202 // do nothing; continue responding to request in single-threaded mode |
200 } |
203 } |
201 else if ( $pid ) |
204 else if ( $pid ) |
202 { |
205 { |
203 // we are the parent, continue listening |
206 // we are the parent, continue listening |
204 $remote = false; |
207 socket_close($remote); |
205 continue; |
208 continue; |
206 } |
209 } |
207 else |
210 else |
208 { |
211 { |
209 // this is the child |
212 // this is the child |
210 define('HTTPD_WS_CHILD', 1); |
213 define('HTTPD_WS_CHILD', 1); |
211 $this->sock = false; |
214 socket_close($this->sock); |
212 } |
215 } |
213 } |
216 } |
214 |
217 |
215 $this->in_keepalive = false; |
218 $this->in_keepalive = false; |
216 |
219 |
253 } |
256 } |
254 |
257 |
255 // enable keep-alive if requested |
258 // enable keep-alive if requested |
256 if ( isset($_SERVER['HTTP_CONNECTION']) && defined('HTTPD_WS_CHILD') ) |
259 if ( isset($_SERVER['HTTP_CONNECTION']) && defined('HTTPD_WS_CHILD') ) |
257 { |
260 { |
258 $this->in_keepalive = ( $_SERVER['HTTP_CONNECTION'] === 'keep-alive' ); |
261 $this->in_keepalive = ( strtolower($_SERVER['HTTP_CONNECTION']) === 'keep-alive' ); |
259 } |
262 } |
260 |
263 |
261 if ( isset($_SERVER['HTTP_AUTHORIZATION']) ) |
264 if ( isset($_SERVER['HTTP_AUTHORIZATION']) ) |
262 { |
265 { |
263 $data = $_SERVER['HTTP_AUTHORIZATION']; |
266 $data = $_SERVER['HTTP_AUTHORIZATION']; |
343 continue; |
346 continue; |
344 } |
347 } |
345 |
348 |
346 $this->send_standard_response($remote, $handler, $uri, $params); |
349 $this->send_standard_response($remote, $handler, $uri, $params); |
347 |
350 |
348 if ( !$this->in_keepalive ) |
351 if ( !$this->in_keepalive && defined('HTTPD_WS_CHILD') ) |
349 { |
352 { |
350 // if ( defined('HTTPD_WS_CHILD') ) |
353 // if ( defined('HTTPD_WS_CHILD') ) |
351 // status('Closing connection'); |
354 // status('Closing connection'); |
|
355 @socket_shutdown($remote); |
352 @socket_close($remote); |
356 @socket_close($remote); |
|
357 status('Exiting child process'); |
353 exit(0); |
358 exit(0); |
354 } |
359 } |
355 else |
360 else if ( defined('HTTPD_WS_CHILD') ) |
356 { |
361 { |
357 // if ( defined('HTTPD_WS_CHILD') ) |
362 // if ( defined('HTTPD_WS_CHILD') ) |
358 // status('Continuing connection'); |
363 // status('Continuing connection'); |
359 @socket_write($remote, "\r\n\r\n"); |
364 @socket_write($remote, "\r\n\r\n"); |
360 } |
365 } |
590 if ( $output == '__break__' ) |
595 if ( $output == '__break__' ) |
591 { |
596 { |
592 return true; |
597 return true; |
593 } |
598 } |
594 |
599 |
|
600 // $this->header('Transfer-encoding: chunked'); |
595 $this->header("Content-length: " . strlen($output)); |
601 $this->header("Content-length: " . strlen($output)); |
596 $headers = implode("\r\n", $this->response_headers); |
602 $headers = implode("\r\n", $this->response_headers); |
597 |
603 |
598 // write headers |
604 // write headers |
599 $this->send_client_headers($socket, $this->response_code, $this->content_type, $headers); |
605 $this->send_client_headers($socket, $this->response_code, $this->content_type, $headers); |
|
606 |
|
607 // chunk output |
|
608 // $output = dechex(strlen($output)) . "\r\n$output"; |
600 |
609 |
601 // write body |
610 // write body |
602 @socket_write($socket, $output); |
611 @socket_write($socket, $output); |
603 |
612 |
604 break; |
613 break; |