modified: LICENSE
[mistral.git] / examples / hello_world_forks.php
blob9571cbe45341cc5a2560f69a0107e98fc44733f2
1 <?php
2 function my_cool_callback($requests) {
3 $requests['HTTP_CONNECTION'] = isset($requests['HTTP_CONNECTION']) ? $requests['HTTP_CONNECTION'] : 'close';
5 $output = "Hello World!";
6 $answer = array('status_code' => '200 OK',
7 'connection' => $requests['HTTP_CONNECTION'],
8 'content-type' => 'text/html',
9 'content-length' => strlen($output),
10 'body' => $output);
11 return $answer;
14 $maxChildren = 4;
15 $startport = 8080;
16 while( $cntChildren < $maxChildren ) {
17 $cntChildren++;
18 $startport++;
20 $pid = pcntl_fork();
21 if ($pid == -1) {
22 echo "Warning: Cannot spawn child process!!!\n";
23 } elseif($pid) {
24 // Parent process
25 } else {
26 echo 'Spawn Child [' . getMyPid() . '] Port ' . $startport . "\n";
27 mistral_init('0.0.0.0', $startport, 5);
28 mistral_register_callback('my_cool_callback');
29 mistral_start();
33 while(true) {
34 sleep(1);