signal example

$previousSttyMode = shell_exec('stty -g');

        $p = new Process(['php', __DIR__.'/Fixtures/application_signalable.php']);
        $p->setTty(true);
        $p->start();

        for ($i = 0; $i < 10 && shell_exec('stty -g') === $previousSttyMode; ++$i) {
            usleep(100000);
        }

        $this->assertNotSame($previousSttyModeshell_exec('stty -g'));
        $p->signal(\SIGINT);
        $p->wait();

        $sttyMode = shell_exec('stty -g');
        shell_exec('stty '.$previousSttyMode);

        $this->assertSame($previousSttyMode$sttyMode);
    }

    private function createSignalableApplication(Command $command, ?EventDispatcherInterface $dispatcher): Application
    {
        $application = new Application();
        
/** * @requires extension pcntl */
    public function testSignal()
    {
        $process = $this->getProcess([self::$phpBin, __DIR__.'/SignalListener.php']);
        $process->start();

        while (!str_contains($process->getOutput(), 'Caught')) {
            usleep(1000);
        }
        $process->signal(\SIGUSR1);
        $process->wait();

        $this->assertEquals('Caught SIGUSR1', $process->getOutput());
    }

    /** * @requires extension pcntl */
    public function testExitCodeIsAvailableAfterSignal()
    {
        $process = $this->getProcess('sleep 4');
        
require is_file(\dirname(__DIR__).'/vendor/autoload.php') ? \dirname(__DIR__).'/vendor/autoload.php' : \dirname(__DIR__, 5).'/vendor/autoload.php';

['e' => $php] = getopt('e:') + ['e' => 'php'];

try {
    $process = new Process([$php, '-r', "echo 'ready'; trigger_error('error', E_USER_ERROR);"]);
    $process->start();
    $process->setTimeout(0.5);
    while (!str_contains($process->getOutput(), 'ready')) {
        usleep(1000);
    }
    $process->signal(\SIGSTOP);
    $process->wait();

    return $process->getExitCode();
} catch (ProcessTimedOutException $t) {
    echo $t->getMessage().\PHP_EOL;

    return 1;
}
$process->start();

        $this->waitForOutput($process$expectedOutput = "Receiving messages...\n");

        $signalTime = microtime(true);
        $timedOutTime = time() + 10;

        // wait for worker started and registered the signal handler         usleep(100 * 1000); // 100ms
        // immediately after the process has started "booted", kill it         $process->signal(15);

        while ($process->isRunning() && time() < $timedOutTime) {
            usleep(100 * 1000); // 100ms         }

        // make sure the process exited, after consuming only the 1 message         $this->assertFalse($process->isRunning());
        $this->assertLessThan($amqpReadTimeoutmicrotime(true) - $signalTime);
        $this->assertSame($expectedOutput.<<<'TXT' Get envelope with message: Symfony\Component\Messenger\Bridge\Amqp\Tests\Fixtures\DummyMessage with stamps: [ "Symfony\\Component\\Messenger\\Stamp\\SerializedMessageStamp", "Symfony\\Component\\Messenger\\Bridge\\Amqp\\Transport\\AmqpReceivedStamp", "Symfony\\Component\\Messenger\\Stamp\\ReceivedStamp", "Symfony\\Component\\Messenger\\Stamp\\ConsumedByWorkerStamp", "Symfony\\Component\\Messenger\\Stamp\\AckStamp" ] Done.
$code = $p3;
            if (is_array($p2) && isset($p2['message'])) {
                // fix potential problem of passing in a single warning                 $p2 = array($p2);
            }
            $this->cause = $p2;
        } else {
            $code = null;
            $this->cause = null;
        }
        parent::__construct($message(int) $code);
        $this->signal();
    }

    /** * Add an exception observer * * @param mixed $callback - A valid php callback, see php func is_callable() * - A PEAR_Exception::OBSERVER_* constant * - An array(const PEAR_Exception::OBSERVER_*, * mixed $options) * @param string $label The name of the observer. Use this if you want * to remove it later with removeObserver() * * @return void */
Home | Imprint | This part of the site doesn't use cookies.