From 100ff45c68a3decb076aa9aa8b80e5b34f339a40 Mon Sep 17 00:00:00 2001 From: Stefan de Konink Date: Sun, 28 Feb 2010 04:17:52 +0100 Subject: [PATCH] Two new examples by Michael --- examples/hello_world_forks.php | 47 ++++++++++++++++++++++++++++++++++ examples/mistral.php | 58 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 examples/hello_world_forks.php create mode 100644 examples/mistral.php diff --git a/examples/hello_world_forks.php b/examples/hello_world_forks.php new file mode 100644 index 0000000..8e09683 --- /dev/null +++ b/examples/hello_world_forks.php @@ -0,0 +1,47 @@ + '200 OK', + 'connection' => $_SERVER['HTTP_CONNECTION'], + 'content-type' => 'text/html', + 'content-length' => strlen($output), + 'body' => $output); + return $answer; + } +} + + +$maxChildren = 4; +$startport = 8080; +while( $cntChildren < $maxChildren ) { + $cntChildren++; + $startport++; + + $pid = pcntl_fork(); + if ($pid == -1) { + echo "Warning: Cannot spawn child process!!!\n"; + } + elseif($pid) { + // Parent process + } + else { + echo 'Spawn Child [' . getMyPid() . '] Port ' . $startport . "\n"; + $app = new HelloWorldApp('0.0.0.0', $startport, 3); + $app->register_callback('HelloWorldApp::main'); + $app->run(); + } +} + +while(true) { + sleep(1); +} +?> diff --git a/examples/mistral.php b/examples/mistral.php new file mode 100644 index 0000000..2cc026c --- /dev/null +++ b/examples/mistral.php @@ -0,0 +1,58 @@ + $parsed_uri['query']); + $_SERVER['argc'] = count($_SERVER['argv']); + $_SERVER['GATEWAY_INTERFACE'] = 'CGI/1.1'; + $_SERVER['SCRIPT_NAME'] = $parsed_uri['path']; + $_SERVER['PHP_SELF'] = $_SERVER['SCRIPT_NAME']; + $_SERVER['PATH_TRANSLATED'] = __PATH__; + $_SERVER['QUERY_STRING'] = $parsed_uri['query']; + $_SERVER['DOCUMENT_ROOT'] = '/'; + if( !isset($_SERVER['HTTP_CONNECTION']) ) { + $_SERVER['HTTP_CONNECTION'] = $_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.1' ? 'keep-alive' : 'close'; + } + } +} +?> -- 2.11.4.GIT