#Swoole starts a service, which processes and threads are started?
## Serv.php (Recommended learning: SWOOLE Video Tutorial )
<?php class Server { private $serv; public function __construct() { $this->serv = new swoole_server("0.0.0.0", 9502); $this->serv->set([ 'worker_num' => 3, 'task_worker_num' => 3, ]); $this->serv->on('Start', function ($serv) { echo "SWOOLE:".SWOOLE_VERSION . " 服务已启动".PHP_EOL; echo "SWOOLE_CPU_NUM:".swoole_cpu_num().PHP_EOL; }); $this->serv->on('Receive', function ($serv, $fd, $from_id, $data) { }); $this->serv->on('Task', function ($serv, $task) { }); $this->serv->on('Finish', function ($serv, $task_id, $data) {}); $this->serv->start(); } } $server = new Server();
The code above is simply speaking, creating a TCP The server has started 3 worker processes and 3 task processes. Because the task function is enabled, the callback functions of the onTask and onFinish events must be registered.
Let’s run it:
Use ps to check it:
The above is the detailed content of Does the swoole service only start one process?. For more information, please follow other related articles on the PHP Chinese website!