Add REQUEST_BODY
[mistral.git] / examples / hello_world_forks.php
blobc0dbca4ad864d97199ed56955c747e3cd2de0c26
1 <?php
2 function my_cool_callback($requests) {
3 $requests['HTTP_CONNECTION'] = isset($requests['HTTP_CONNECTION']) ? $requests['HTTP_CONNECTION'] : 'close';
5 $output = "Hello World! PID: " . getMyPid();
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 $cntChildren = 0;
15 $maxChildren = 4;
16 $startport = 8080;
17 while( $cntChildren < $maxChildren ) {
18 $cntChildren++;
19 $startport++;
21 $pid = pcntl_fork();
22 if ($pid == -1) {
23 echo "Warning: Cannot spawn child process!!!\n";
24 } elseif($pid) {
25 // Parent process
26 } else {
27 echo '[' . getMyPid() . '] Child process listening on port ' . $startport . "\n";
28 mistral_init('0.0.0.0', $startport, 5);
29 mistral_register_callback('my_cool_callback');
30 mistral_start();
34 while(true) {
35 sleep(1);