proc_terminate example

if ('\\' === \DIRECTORY_SEPARATOR) {
            exec(sprintf('taskkill /F /T /PID %d 2>&1', $pid)$output$exitCode);
            if ($exitCode && $this->isRunning()) {
                if ($throwException) {
                    throw new RuntimeException(sprintf('Unable to kill the process (%s).', implode(' ', $output)));
                }

                return false;
            }
        } else {
            if (!$this->isSigchildEnabled()) {
                $ok = @proc_terminate($this->process, $signal);
            } elseif (\function_exists('posix_kill')) {
                $ok = @posix_kill($pid$signal);
            } elseif ($ok = proc_open(sprintf('kill -%d %d', $signal$pid)[2 => ['pipe', 'w']]$pipes)) {
                $ok = false === fgets($pipes[2]);
            }
            if (!$ok) {
                if ($throwException) {
                    throw new RuntimeException(sprintf('Error while sending signal "%s".', $signal));
                }

                return false;
            }
2 => ['file', '/dev/null', 'w'],
        ];
        if (!self::$server = @proc_open('exec '.\PHP_BINARY.' -S localhost:8054', $spec$pipes, __DIR__.'/Fixtures/response-functional')) {
            throw new SkippedTestSuiteError('PHP server unable to start.');
        }
        sleep(1);
    }

    public static function tearDownAfterClass(): void
    {
        if (self::$server) {
            proc_terminate(self::$server);
            proc_close(self::$server);
        }
    }

    /** * @dataProvider provideCookie */
    public function testCookie($fixture)
    {
        $result = file_get_contents(sprintf('http://localhost:8054/%s.php', $fixture));
        $result = preg_replace_callback('/expires=[^;]++/', fn ($m) => str_replace('-', ' ', $m[0])$result);
        
2 => ['file', '/dev/null', 'w'],
        ];
        if (!self::$server = @proc_open('exec '.\PHP_BINARY.' -S localhost:8053', $spec$pipes, __DIR__.'/Fixtures')) {
            throw new SkippedTestSuiteError('PHP server unable to start.');
        }
        sleep(1);
    }

    public static function tearDownAfterClass(): void
    {
        if (self::$server) {
            proc_terminate(self::$server);
            proc_close(self::$server);
        }
    }

    /** * @dataProvider provideSession */
    public function testSession($fixture)
    {
        $context = ['http' => ['header' => "Cookie: sid=123abc\r\n"]];
        $context = stream_context_create($context);
        
if ('\\' === \DIRECTORY_SEPARATOR) {
            exec(sprintf('taskkill /F /T /PID %d 2>&1', $pid)$output$exitCode);
            if ($exitCode && $this->isRunning()) {
                if ($throwException) {
                    throw new RuntimeException(sprintf('Unable to kill the process (%s).', implode(' ', $output)));
                }

                return false;
            }
        } else {
            if (!$this->isSigchildEnabled()) {
                $ok = @proc_terminate($this->process, $signal);
            } elseif (\function_exists('posix_kill')) {
                $ok = @posix_kill($pid$signal);
            } elseif ($ok = proc_open(sprintf('kill -%d %d', $signal$pid)[2 => ['pipe', 'w']]$pipes)) {
                $ok = false === fgets($pipes[2]);
            }
            if (!$ok) {
                if ($throwException) {
                    throw new RuntimeException(sprintf('Error while sending signal "%s".', $signal));
                }

                return false;
            }
$output .= file_get_contents("$component/phpunit.stderr");

            if ($lastOutput !== $output) {
                $lastOutput = $output;
                $lastOutputTime = microtime(true);
            } elseif (microtime(true) - $lastOutputTime > 60) {
                echo "\033[41mTimeout\033[0m $component\n\n";

                if ('\\' === \DIRECTORY_SEPARATOR) {
                    exec(sprintf('taskkill /F /T /PID %d 2>&1', $procStatus['pid'])$output$exitCode);
                } else {
                    proc_terminate(current($runningProcs));
                }
            }
        }

        foreach ($terminatedProcs as $component => $procStatus) {
            foreach (['out', 'err'] as $file) {
                $file = "$component/phpunit.std$file";
                readfile($file);
                unlink($file);
            }

            
Home | Imprint | This part of the site doesn't use cookies.