Swoole Server start

public void Swoole\Server::start ( void )

Alias: Swoole\Server->start()

Start the Swoole Server, it will create worker_num + 2 processes by default:

  • main process: running multiple threads reactor, receive new connections and assign connections to worker processes
  • manager process: managing the worker processes
  • worker_num * child processes: process the data and business logics

Parameter

void

Return

The result if the Swoole Server starts successfully

Example

<?php
$server = new Swoole\Server("127.0.0.1", 9501);
$server->on('connect', function ($server, $fd){
    echo "New connection established: #{$fd}.\n";
});
$server->on('receive', function ($server, $fd, $from_id, $data) {
    $server->send($fd, "Echo to #{$fd}: \n".$data);
    $server->close($fd);
});
$server->on('close', function ($server, $fd) {
    echo "Connection closed: #{$fd}.\n";
});
$server->start();