Skip to content

Conversation

@pavog
Copy link
Member

@pavog pavog commented May 28, 2025

Problem

In my setup, I use TaskMaster in a command that I execute from the CLI.
In my command, I use PCNTL to listen for signals such as SIGINT and then gracefully terminate the command. As soon as you press CTRL+C, the function is executed.
However, this also triggers the PHP warning from Taskmaster:
PHP Warning: stream_select(): Unable to select [4]: Interrupted system call (max_fd=10) in .../vendor/aternos/taskmaster/src/Taskmaster.php on line 291

Example code

SleepTask.php

<?php
namespace Aternos\Test;

class SleepTask extends \Aternos\Taskmaster\Task\Task {

    public function __construct(protected int $id)
    {
    }

    public function run(): void
    {
        echo "Task {$this->id} is sleeping...\n";
        sleep(3);
    }
}

test-command.php

<?php

require_once __DIR__ . '/vendor/autoload.php';

pcntl_async_signals(true);

function sig_handler($signo)
{
    switch ($signo) {
        case SIGINT:
            echo "Caught SIGINT, shutting down in 3 seconds...\n";
            sleep(3);
            echo "Exiting now...\n";
            exit;
        default:
            // handle all other signals
    }
}

pcntl_signal(SIGINT, "sig_handler");

$taskmaster = new \Aternos\Taskmaster\Taskmaster();
$taskmaster->autoDetectWorkers(4);

for ($i = 0; $i < 8; $i++) {
    $taskmaster->runTask(new \Aternos\Test\SleepTask($i));
}

$taskmaster->wait()->stop();

Output

> php test-command.php
Task 0 is sleeping...
Task 2 is sleeping...
Task 3 is sleeping...
Task 1 is sleeping...
^C
PHP Warning:  stream_select(): Unable to select [4]: Interrupted system call (max_fd=10) in .../vendor/aternos/taskmaster/src/Taskmaster.php on line 291
Caught SIGINT, shutting down in 3 seconds...
Exiting now...

Solution

To prevent this warning from being displayed, I add the @ sign to the stream_select call. This suppresses the warning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant