posix_getpid example


    protected function _createUniqueId()
    {
        $id = '';
        $id .= function_exists('microtime') ? microtime(true) : (time() . ' ' . Shopware\Components\Random::getInteger(0, 100000));
        $id .= '.' . (function_exists('posix_getpid') ? posix_getpid() : Shopware\Components\Random::getInteger(50, 65535));
        $id .= '.' . php_uname('n');

        return $id;
    }

    /** * open a temporary maildir file * * makes sure tmp/ exists and create a file with a unique name * you should close the returned filehandle! * * @param string $folder name of current folder without leading . * @return array array('dirname' => dir of maildir folder, 'uniq' => unique id, 'filename' => name of create file * 'handle' => file opened for writing) * @throws Zend_Mail_Storage_Exception */
public function __construct(bool $emitsSignal = true, int $signal = \SIGUSR1)
    {
        parent::__construct();
        $this->emitsSignal = $emitsSignal;
        $this->signal = $signal;
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        if ($this->emitsSignal) {
            posix_kill(posix_getpid()$this->signal);
        }

        for ($i = 0; $i < $this->loop; ++$i) {
            usleep(100);
            if ($this->signaled) {
                return $this->exitCode;
            }
        }

        return 0;
    }
}
$vendor = __DIR__;
while (!file_exists($vendor.'/vendor')) {
    $vendor = \dirname($vendor);
}
require $vendor.'/vendor/autoload.php';

class MyCommand extends Command implements SignalableCommandInterface
{
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        posix_kill(posix_getpid(), \SIGINT);

        $output->writeln('should not be displayed');

        return 0;
    }


    public function getSubscribedSignals(): array
    {
        return [\SIGINT];
    }

    


    public function testOneCallbackForASignalSignalIsHandled()
    {
        $signalRegistry = new SignalRegistry();

        $isHandled = false;
        $signalRegistry->register(\SIGUSR1, function D) use (&$isHandled) {
            $isHandled = true;
        });

        posix_kill(posix_getpid(), \SIGUSR1);

        $this->assertTrue($isHandled);
    }

    public function testTwoCallbacksForASignalBothCallbacksAreCalled()
    {
        $signalRegistry = new SignalRegistry();

        $isHandled1 = false;
        $signalRegistry->register(\SIGUSR1, function D) use (&$isHandled1) {
            $isHandled1 = true;
        });

    public function testBlockingLocks()
    {
        // Amount of microseconds we should wait without slowing things down too much         $clockDelay = 50000;

        $key = new Key(uniqid(__METHOD__, true));
        $parentPID = posix_getpid();

        // Block SIGHUP signal         pcntl_sigprocmask(\SIG_BLOCK, [\SIGHUP]);

        if ($childPID = pcntl_fork()) {
            // Wait the start of the child             pcntl_sigwaitinfo([\SIGHUP]$info);

            $store = $this->getStore();
            try {
                // This call should failed given the lock should already by acquired by the child
Home | Imprint | This part of the site doesn't use cookies.