stopAll

void Worker::stopAll(void)

Stops the current process and exits.

Note
Worker::stopAll() is used to stop the current process, and once the current process exits, the main process will immediately start a new process. If you want to stop the entire workerman service, please call posix_kill(posix_getppid(), SIGINT)

Parameters

No parameters

Return value

No return value

Example max_request

In the following example, the child process executes stopAll to exit after handling 1000 requests, allowing it to restart a fresh process. This is similar to the max_request attribute in php-fpm, primarily used to address memory leak issues caused by bugs in PHP business code.

start.php

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

// Each process handles a maximum of 1000 requests
define('MAX_REQUEST', 1000);

$http_worker = new Worker("http://0.0.0.0:2345");
$http_worker->onMessage = function(TcpConnection $connection, $data)
{
    // Number of requests already processed
    static $request_count = 0;

    $connection->send('hello http');
    // If the number of requests reaches 1000
    if(++$request_count >= MAX_REQUEST)
    {
        /*
         * Exit the current process, the main process will immediately restart a fresh process to supplement it
         * thus completing the process restart
         */
        Worker::stopAll();
    }
};

Worker::runAll();