Gentoo solution
[mistral.git] / examples / hello_world_forks.php
blob8e09683fc7ab542c28a2b366d217e2862369d849
1 <?php
2 class HelloWorldApp extends Mistral
4 public static function main($http_request) {
5 #print_r($http_request);
7 #xhprof_enable();
8 self::parse_headers($http_request);
9 #$xhprof_data = xhprof_disable();
10 #print_r($xhprof_data);
12 $output = "Hello World!";
13 $answer = array('status_code' => '200 OK',
14 'connection' => $_SERVER['HTTP_CONNECTION'],
15 'content-type' => 'text/html',
16 'content-length' => strlen($output),
17 'body' => $output);
18 return $answer;
23 $maxChildren = 4;
24 $startport = 8080;
25 while( $cntChildren < $maxChildren ) {
26 $cntChildren++;
27 $startport++;
29 $pid = pcntl_fork();
30 if ($pid == -1) {
31 echo "Warning: Cannot spawn child process!!!\n";
33 elseif($pid) {
34 // Parent process
36 else {
37 echo 'Spawn Child [' . getMyPid() . '] Port ' . $startport . "\n";
38 $app = new HelloWorldApp('0.0.0.0', $startport, 3);
39 $app->register_callback('HelloWorldApp::main');
40 $app->run();
44 while(true) {
45 sleep(1);