$read = $write = array(); while (true) { $events = $poll->poll($read, $write); foreach ($read as $socket) { $zmsg = new Zmsg($socket); $zmsg->recv(); if ($socket === $frontend) { $zmsg->push("W"); $zmsg->set_socket($backend)->send(); } elseif ($socket === $backend) { $zmsg->pop(); $zmsg->push("C"); $zmsg->set_socket($frontend)->send(); } } } } $wpid = pcntl_fork(); if ($wpid == 0) { worker_task(); exit; } $bpid = pcntl_fork(); if ($bpid == 0) { broker_task(); exit; } sleep(1); client_task(); posix_kill($wpid, SIGKILL); posix_kill($bpid, SIGKILL);
function main() { for ($num_clients = 0; $num_clients < 3; $num_clients++) { $pid = pcntl_fork(); if ($pid == 0) { client_task(); exit; } } $pid = pcntl_fork(); if ($pid == 0) { server_task(); exit; } }