Home > PHP Framework > Swoole > body text

Does the swoole service only start one process?

(*-*)浩
Release: 2019-12-16 11:59:41
Original
2066 people have browsed it

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();
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template