Swoole\Process\Pool->on('stop', fn)

Declaration

<?php
Swoole\Process\Pool->on('stop', callback $callback)

Parameters

event

The event name

callback

callback function

Return

success

if success, it returns TRUE, otherwise it returns FALSE.

Description

Executue the callback function when the Process Pool is started.

Example

<?php

$workerNum = 10;
$pool = new Swoole\Process\Pool($workerNum);

$pool->on('stop', function() {
    echo "Process Pool is stopping.\n";
});

$pool->on("WorkerStart", function ($pool, $workerId) {
    echo "Worker#{$workerId} is started\n";
    $redis = new Redis();
    $redis->pconnect('127.0.0.1', 6379);
    $key = "key1";
    while (true) {
         $msgs = $redis->brpop($key, 2);
         if ( $msgs == null) continue;
         var_dump($msgs);
     }
});

$pool->on("WorkerStop", function ($pool, $workerId) {
    echo "Worker#{$workerId} is stopped\n";
});

$pool->start();