runAll

void Worker::runAll(void)

Run all Worker instances.

Note:

After calling Worker::runAll(), it will block permanently, which means that any code located after Worker::runAll() will not be executed. All Worker instances should be instantiated before calling Worker::runAll().

Parameters

No parameters

Return Value

No return value

Example Run Multiple Worker Instances

start.php

<?php
use Workerman\Worker;
use Workerman\Connection\TcpConnection;
require_once __DIR__ . '/vendor/autoload.php';

$http_worker = new Worker("http://0.0.0.0:2345");
$http_worker->onMessage = function(TcpConnection $connection, $data)
{
    $connection->send('hello http');
};

$ws_worker = new Worker('websocket://0.0.0.0:4567');
$ws_worker->onMessage = function(TcpConnection $connection, $data)
{
    $connection->send('hello websocket');
};

// Run all Worker instances
Worker::runAll();

Note:

The Windows version of Workerman does not support instantiating multiple Workers in the same file. The example above cannot run under the Windows version of Workerman.

The Windows version of Workerman requires multiple Worker instances to be initialized in different files, as shown below.

start_http.php

<?php
use Workerman\Worker;
use Workerman\Connection\TcpConnection;
require_once __DIR__ . '/vendor/autoload.php';

$http_worker = new Worker("http://0.0.0.0:2345");
$http_worker->onMessage = function(TcpConnection $connection, $data)
{
    $connection->send('hello http');
};

// Run all Worker instances (there's only one instance here)
Worker::runAll();

start_websocket.php

<?php
use Workerman\Worker;
use Workerman\Connection\TcpConnection;
require_once __DIR__ . '/vendor/autoload.php';

$ws_worker = new Worker('websocket://0.0.0.0:4567');
$ws_worker->onMessage = function(TcpConnection $connection, $data)
{
    $connection->send('hello websocket');
};

// Run all Worker instances (there's only one instance here)
Worker::runAll();