Home >PHP Framework >Swoole >Does the swoole service only start one process?

Does the swoole service only start one process?

(*-*)浩
(*-*)浩Original
2019-12-16 11:59:412141browse

Does the swoole service only start one process?

#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([
            &#39;worker_num&#39;      => 3,
            &#39;task_worker_num&#39; => 3,
        ]);
        $this->serv->on(&#39;Start&#39;, function ($serv) {
            echo "SWOOLE:".SWOOLE_VERSION . " 服务已启动".PHP_EOL;
            echo "SWOOLE_CPU_NUM:".swoole_cpu_num().PHP_EOL;
        });
        $this->serv->on(&#39;Receive&#39;, function ($serv, $fd, $from_id, $data) { });
        $this->serv->on(&#39;Task&#39;, function ($serv, $task) { });
        $this->serv->on(&#39;Finish&#39;, 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:

Does the swoole service only start one process?

Use ps to check it:

Does the swoole service only start one process?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What is the swoole port?Next article:What is the swoole port?