equal
deleted
inserted
replaced
158 */ |
158 */ |
159 |
159 |
160 var $socket_initted = false; |
160 var $socket_initted = false; |
161 |
161 |
162 /** |
162 /** |
|
163 * The list of child processes spawned by this server. |
|
164 * @var array |
|
165 */ |
|
166 |
|
167 var $child_list = array(); |
|
168 |
|
169 /** |
|
170 * The parent process's PID |
|
171 * @var int |
|
172 */ |
|
173 |
|
174 var $parent_pid = 0; |
|
175 |
|
176 /** |
163 * Constructor. |
177 * Constructor. |
164 * @param string IPv4 address to bind to |
178 * @param string IPv4 address to bind to |
165 * @param int Port number |
179 * @param int Port number |
166 * @param int If port is under 1024, specify a user ID/name to switch to here |
180 * @param int If port is under 1024, specify a user ID/name to switch to here |
167 * @param int If port is under 1024, specify a group ID/name to switch to here |
181 * @param int If port is under 1024, specify a group ID/name to switch to here |
252 status('Successfully switched user ID'); |
266 status('Successfully switched user ID'); |
253 } |
267 } |
254 |
268 |
255 $this->bind_address = $address; |
269 $this->bind_address = $address; |
256 $this->server_string = "PhpHttpd/" . HTTPD_VERSION . " PHP/" . PHP_VERSION . "\r\n"; |
270 $this->server_string = "PhpHttpd/" . HTTPD_VERSION . " PHP/" . PHP_VERSION . "\r\n"; |
|
271 $this->parent_pid = getmypid(); |
257 |
272 |
258 // create a UUID |
273 // create a UUID |
259 $uuid_base = md5(microtime() . ( function_exists('mt_rand') ? mt_rand() : rand() )); |
274 $uuid_base = md5(microtime() . ( function_exists('mt_rand') ? mt_rand() : rand() )); |
260 $this->uuid = substr($uuid_base, 0, 8) . '-' . |
275 $this->uuid = substr($uuid_base, 0, 8) . '-' . |
261 substr($uuid_base, 8, 4) . '-' . |
276 substr($uuid_base, 8, 4) . '-' . |
335 } |
350 } |
336 else if ( $pid ) |
351 else if ( $pid ) |
337 { |
352 { |
338 // we are the parent, continue listening |
353 // we are the parent, continue listening |
339 socket_close($remote); |
354 socket_close($remote); |
|
355 $this->child_list[] = $pid; |
340 continue; |
356 continue; |
341 } |
357 } |
342 else |
358 else |
343 { |
359 { |
344 // this is the child |
360 // this is the child |
355 // read request |
371 // read request |
356 $last_line = ''; |
372 $last_line = ''; |
357 $client_headers = ''; |
373 $client_headers = ''; |
358 if ( defined('HTTPD_WS_CHILD') ) |
374 if ( defined('HTTPD_WS_CHILD') ) |
359 { |
375 { |
360 if ( !@socket_set_timeout($remote, HTTPD_KEEP_ALIVE_TIMEOUT) ) |
376 @socket_set_timeout($remote, HTTPD_KEEP_ALIVE_TIMEOUT); |
361 { |
|
362 status('stream_set_timeout() on $remote failed.'); |
|
363 var_dump($remote); |
|
364 } |
|
365 } |
377 } |
366 if ( $line = @socket_read($remote, 1024, PHP_NORMAL_READ) ) |
378 if ( $line = @socket_read($remote, 1024, PHP_NORMAL_READ) ) |
367 { |
379 { |
368 do |
380 do |
369 { |
381 { |