diff --git a/examples/server.php b/examples/server.php index 249f624dc03..64026af80b5 100644 --- a/examples/server.php +++ b/examples/server.php @@ -2,11 +2,11 @@ $serv = new swoole_server("0.0.0.0", 9501); // $serv->addlistener('0.0.0.0', 9502, SWOOLE_SOCK_UDP); $serv->set(array( - 'worker_num' => 4, + 'worker_num' => 1, //'open_eof_check' => true, //'package_eof' => "\r\n", //'ipc_mode' => 2, - //'task_worker_num' => 2, + 'task_worker_num' => 1, //'task_ipc_mode' => 1, //'dispatch_mode' => 1, //'daemonize' => 1, @@ -34,6 +34,7 @@ function my_onShutdown($serv) function my_onTimer($serv, $interval) { + //echo microtime(true)."\n"; my_log("Server:Timer Call.Interval=$interval"); } @@ -51,18 +52,22 @@ function my_onConnect($serv, $fd, $from_id) function my_onWorkerStart($serv, $worker_id) { global $argv; - if($worker_id >= $serv->setting['worker_num']) { + if($worker_id >= $serv->setting['worker_num']) + { swoole_set_process_name("php {$argv[0]}: task"); - } else { + } + else + { swoole_set_process_name("php {$argv[0]}: worker"); } echo "WorkerStart: MasterPid={$serv->master_pid}|Manager_pid={$serv->manager_pid}"; echo "|WorkerId={$serv->worker_id}|WorkerPid={$serv->worker_pid}\n"; - if ($worker_id == 0) + if ($worker_id == 1) { - $serv->addtimer(2000); //500ms - //$serv->addtimer(6000); //500ms + $serv->addtimer(2000); + $serv->addtimer(6000); + //echo microtime(true)."\n"; //var_dump($serv->gettimer()); } } diff --git a/examples/udp_server.php b/examples/udp_server.php index 1c5b5e0246c..f247c770735 100644 --- a/examples/udp_server.php +++ b/examples/udp_server.php @@ -1,5 +1,5 @@ set(array( 'worker_num' => 1, //worker process num //'log_file' => '/tmp/swoole.log', diff --git a/src/os/timer.c b/src/os/timer.c index 42d06d58313..05365b82b75 100644 --- a/src/os/timer.c +++ b/src/os/timer.c @@ -148,8 +148,8 @@ static int swTimer_signal_set(swTimer *timer, int interval) timer_set.it_interval.tv_sec = sec; timer_set.it_interval.tv_usec = msec * 1000; - timer_set.it_value.tv_sec = now.tv_sec + sec; - timer_set.it_value.tv_usec = now.tv_usec + timer_set.it_interval.tv_usec; + timer_set.it_value.tv_sec = sec; + timer_set.it_value.tv_usec = timer_set.it_interval.tv_usec; if (timer_set.it_value.tv_usec > 1e6) {