stop() public method

Stops the process.
public stop ( integer | float $timeout = 10, integer $signal = null ) : integer
$timeout integer | float The timeout in seconds
$signal integer A POSIX signal to send in case the process has not stop at timeout, default is SIGKILL (9)
return integer The exit-code of the process
コード例 #1
0
 protected static function stopServer()
 {
     if (!static::$enabled) {
         return;
     }
     self::$server->stop();
 }
コード例 #2
0
ファイル: ProcessRunner.php プロジェクト: shadowhand/humbug
 /**
  * @param Process $process
  * @param AdapterAbstract $testFrameworkAdapter
  * @param callable $onProgressCallback
  *
  * @return bool
  */
 public function run(Process $process, AdapterAbstract $testFrameworkAdapter, \Closure $onProgressCallback = null)
 {
     $hasFailure = false;
     $process->run(function ($out, $data) use($process, $testFrameworkAdapter, $onProgressCallback, &$hasFailure) {
         if ($out == Process::ERR) {
             $hasFailure = true;
             $process->stop();
             return;
         }
         if ($hasFailure) {
             return;
         }
         if (!$testFrameworkAdapter->ok($data)) {
             $hasFailure = true;
             $process->stop();
             return;
         }
         $oksCount = $testFrameworkAdapter->hasOks($data);
         if ($oksCount !== false && $onProgressCallback) {
             $onProgressCallback($oksCount);
         }
     });
     $process->stop();
     return $hasFailure;
 }
コード例 #3
0
 /**
  * @inheritdoc
  */
 public function forceStop()
 {
     if (!$this->stopped) {
         $this->process->stop();
     }
     $this->stopped = true;
 }
コード例 #4
0
 public function stop()
 {
     while ($this->isRunning()) {
         $this->serverProcess->stop($this->timeout, SIGINT);
         // it needs some time to stop
         usleep(10);
     }
 }
コード例 #5
0
ファイル: Exec.php プロジェクト: stefanhuber/Robo
 protected function stop()
 {
     if ($this->background && $this->process->isRunning()) {
         $this->process->stop();
         $this->printTaskInfo("Stopped <info>" . $this->getCommand() . "</info>");
     }
 }
コード例 #6
0
ファイル: ServerTest.php プロジェクト: apigraf/xsolla-sdk-php
 /**
  * @dataProvider cbProvider
  */
 public function testResponse($expectedStatusCode, $expectedResponseContent, $request, $testCase, $testHeaders)
 {
     $process = new Process('php -S [::1]:8999', __DIR__ . '/../../resources');
     $process->start();
     sleep(1);
     $signature = sha1($request . ServerMock::PROJECT_SECRET_KEY);
     $headers = null;
     if ($testHeaders) {
         $headers = $testHeaders;
     } else {
         $headers = array('Authorization' => 'Signature ' . $signature);
     }
     $request = $this->guzzleClient->post('/webhook_server.php?test_case=' . $testCase, $headers, $request);
     try {
         $response = $request->send();
     } catch (BadResponseException $e) {
         $process->stop();
         $response = $e->getResponse();
     }
     static::assertSame($expectedResponseContent, $response->getBody(true));
     static::assertSame($expectedStatusCode, $response->getStatusCode());
     static::assertArrayHasKey('x-xsolla-sdk', $response->getHeaders());
     static::assertSame(Version::getVersion(), (string) $response->getHeader('x-xsolla-sdk'));
     static::assertArrayHasKey('content-type', $response->getHeaders());
     if (204 === $response->getStatusCode()) {
         static::assertStringStartsWith('text/plain', (string) $response->getHeader('content-type'));
     } else {
         static::assertStringStartsWith('application/json', (string) $response->getHeader('content-type'));
     }
 }
コード例 #7
0
ファイル: Exec.php プロジェクト: jjok/Robo
 protected function stop()
 {
     if ($this->background && $this->process->isRunning()) {
         $this->process->stop();
         $this->printTaskInfo("Stopped {command}", ['command' => $this->getCommand()]);
     }
 }
コード例 #8
0
ファイル: Exec.php プロジェクト: sliver/Robo
 public function stop()
 {
     if ($this->background && $this->process->isRunning()) {
         $this->process->stop();
         $this->printTaskInfo("stopped <info>{$this->command}</info>");
     }
 }
コード例 #9
0
 /**
  * Terminate current process
  * 
  * @param int $timeout
  * @param int $signal
  */
 protected function _terminate($timeout = 10, $signal = 15)
 {
     foreach ($this->_getPidRecursive($this->getPid()) as $pid) {
         posix_kill($pid, $signal);
     }
     parent::stop($timeout, $signal);
 }
コード例 #10
0
 /**
  * Kills the connection
  */
 public function __destruct()
 {
     if ($this->output->isVerbose()) {
         $this->writeln("Closing SauceLabs tunnel.");
     }
     if (null !== $this->process) {
         $this->process->stop();
     }
 }
コード例 #11
0
ファイル: ProcessRequestTest.php プロジェクト: naroga/querker
 public function testRequest404()
 {
     $process = new Process((new PhpExecutableFinder())->find() . ' -S 127.0.0.1:1337 -t ' . realpath(__DIR__));
     $process->start();
     sleep(1);
     $request = new RequestProcess(new Request('GET', 'http://127.0.0.1:1337/InexistingRequest.php'));
     $this->assertEquals($request->execute(), false);
     $this->assertEquals($request->getError()['status'], 404);
     $process->stop();
 }
コード例 #12
0
 public function testFileDriverWithArrayArgument()
 {
     $fileLock = new File('lock');
     $fileLock->clearLocks();
     $p = new Process('/usr/bin/php Tests/FileLockCommand.php test:file -s 1');
     $p->start();
     $decorator = new Decorator(new TestService(), 'test_service');
     $lock = new Lock();
     $lock->setDriver($fileLock)->setMethod('sleep')->setArgumentIndex(1);
     $decorator->addLock($lock);
     $decorator->sleep(1, array(1));
     $p->stop();
     return $this->assertTrue(true);
 }
コード例 #13
0
ファイル: Server.php プロジェクト: tillk/vufind
 /**
  * Stops the server process
  * @link https://github.com/symfony/Process
  */
 public function stop()
 {
     if (null === $this->process) {
         return;
     }
     if (!$this->isRunning()) {
         return;
     }
     if (null !== $this->getConnection()) {
         // Force a 'clean' exit
         // See: http://stackoverflow.com/a/5266208/187954
         $this->doEvalJS($this->getConnection(), 'process.exit(0);');
         $this->process->stop();
         $this->process = null;
     }
 }
コード例 #14
0
 /**
  * Fire and forget a command. It will be executed asynchronously, but you can get its output via the $callback.
  * 
  * @param string $cmd Command to be fired.
  * @param callable $callback [optional] Callback function that will be called periodically during command's execution
  *                            and will take two arguments: 1st is a string buffer output and 2nd is bool error.
  *                            You can return (bool) false from the callback to stop the running command.
  */
 public function fire($cmd, $callback = null)
 {
     $process = new SymfonyProcess($cmd);
     $process->start();
     // if callback is defined then call it periodically
     if (is_callable($callback)) {
         while ($process->isRunning()) {
             // call the callback
             $continue = call_user_func_array($callback, array($process->getIncrementalOutput()));
             // if callback returned false then stop the process
             if ($continue === false) {
                 $process->stop(3, SIGINT);
             }
         }
     }
 }
コード例 #15
0
ファイル: ClientTest.php プロジェクト: mhlavac/gearman
 public function testClient()
 {
     $process = new Process("gearman -w -f replace -- sed 's/__replace__/the best/g'");
     $process->start();
     try {
         $this->assertEquals('php is the best', $this->client->doNormal('replace', 'php is __replace__'));
         $this->assertEquals('php is the best', $this->client->doLow('replace', 'php is __replace__'));
         $this->assertEquals('php is the best', $this->client->doHigh('replace', 'php is __replace__'));
         $this->client->doBackground('replace', 'php is __replace__');
         $this->client->doHighBackground('replace', 'php is __replace__');
         $this->client->doLowBackground('replace', 'php is __replace__');
     } catch (Exception\CouldNotConnectException $e) {
         $this->markTestSkipped('Skipped, please start Gearman on port ' . Connection::DEFAULT_PORT . ' to be able to run this test');
     }
     $process->stop();
 }
コード例 #16
0
 public function testSpeed()
 {
     $queueTypes = ['redis', 'predis', 'rabbitMQ'];
     $queueFactory = new QueueFactory();
     $messageCount = 200;
     $threadCount = 4;
     $type = 'benchmark-sum';
     $workerScript = __DIR__ . '/benchmark-worker.php';
     $results = [];
     foreach ($queueTypes as $queueType) {
         $queue = $queueFactory->make($queueType);
         $transformer = new TaskMessageSerializeTransformer();
         $executor = new Executor(new TaskScheduler($queue, $transformer, $transformer));
         /** @var Process[] $threads */
         $threads = [];
         for ($i = 0; $i < $threadCount; $i++) {
             $thread = new Process('php ' . $workerScript . ' ' . $queueType . ' ' . $type);
             $thread->start();
             $threads[] = $thread;
         }
         sleep(1);
         $stopwatch = Stopwatch::createStarted();
         /** @var FutureResult[] $futureResults */
         $futureResults = [];
         for ($i = 0; $i < $messageCount; $i++) {
             $futureResults[] = $executor->submit($type, SumTask::class, [$i, $i + 1]);
         }
         $stopwatch->pause();
         $submitTime = $stopwatch->getElapsedSeconds();
         $stopwatch->resume();
         foreach ($futureResults as $futureResult) {
             $futureResult->getResult();
         }
         $stopwatch->stop();
         $totalTime = $stopwatch->getElapsedSeconds();
         foreach ($threads as $thread) {
             $thread->stop();
         }
         $results[$queueType] = [$totalTime, $submitTime];
     }
     foreach ($results as $queueType => list($totalTime, $submitTime)) {
         $this->assertGreaterThan(0, $totalTime);
         $totalTime = number_format($totalTime, 2);
         $submitTime = number_format($submitTime, 2);
         echo "{$queueType}: total = {$totalTime} seconds, submit = {$submitTime} seconds\n";
     }
 }
コード例 #17
0
ファイル: ServerTest.php プロジェクト: kohabi/quake-query
 private function startProcess($port, $respond, $callback)
 {
     $env = array('PORT' => $port, 'RESPOND' => $respond);
     $process = new Process('php tests/bin/server.php', null, $env);
     $process->start();
     // give it time to start
     while ($process->getIncrementalOutput() !== 'started') {
         usleep(100);
     }
     try {
         $callback();
     } catch (Exception $e) {
         $process->signal(SIGKILL);
         $process->stop();
         throw $e;
     }
 }
コード例 #18
0
 /**
  * @AfterScenario
  * @param ScenarioEvent $event
  */
 public function stopCapture(ScenarioEvent $event)
 {
     if ($this->captureProcess !== NULL) {
         $tmpFilePath = $this->getTmpFilename();
         $failedCapturePath = rtrim($this->reportsPath, '/') . '/' . strtr($event->getScenario()->getTitle(), array(' ' => '_', '.' => '_')) . '.mp4';
         $this->captureProcess->stop(3, SIGTERM);
         if (file_exists($tmpFilePath)) {
             if ($event->getResult() === StepEvent::FAILED) {
                 if (!is_dir(dirname($failedCapturePath))) {
                     mkdir(dirname($failedCapturePath), 0777, TRUE);
                 }
                 if (file_exists($failedCapturePath)) {
                     unlink($failedCapturePath);
                 }
                 rename($tmpFilePath, $failedCapturePath);
             } else {
                 unlink($tmpFilePath);
             }
         }
     }
     $this->captureProcess = NULL;
 }
コード例 #19
0
ファイル: SpeedTest.php プロジェクト: mjphaynes/php-resque
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     Resque\Redis::setConfig(array('namespace' => 'resque:speedtest'));
     $testTime = (int) $input->getOption('time') ?: 5;
     @unlink(RESQUE_DIR . '/test/speed/output.log');
     $process = new Process(RESQUE_BIN_DIR . '/resque worker:start -c ' . RESQUE_DIR . '/test/speed/config.yml');
     $start = microtime(true);
     $process->start();
     do {
         $this->setProgress($output, Resque::stats(), $testTime, $start);
         usleep(500);
     } while ($process->isRunning() and $testTime > microtime(true) - $start);
     $process->stop(0, SIGTERM);
     if (!$process->isSuccessful()) {
         list($error) = explode('Exception trace:', $process->getErrorOutput());
         $output->write('<error>' . $error . '</error>');
     }
     // Clear down Redis
     $redis = Resque\Redis::instance();
     $keys = $redis->keys('*');
     foreach ($keys as $key) {
         $redis->del($key);
     }
 }
コード例 #20
0
ファイル: LocalWebServer.php プロジェクト: bamarni/gastonjs
 /**
  * When collecting make the stuff die
  */
 public function __destruct()
 {
     echo "Stopping the local server...\n";
     $this->process->stop();
 }
コード例 #21
0
ファイル: ProcessTest.php プロジェクト: hason/symfony
 /**
  * @dataProvider provideVariousIncrementals
  */
 public function testIncrementalOutputDoesNotRequireAnotherCall($stream, $method)
 {
     $process = new Process(self::$phpBin . ' -r ' . escapeshellarg('$n = 0; while ($n < 3) { file_put_contents(\'' . $stream . '\', $n, 1); $n++; usleep(1000); }'), null, null, null, null);
     $process->start();
     $result = '';
     $limit = microtime(true) + 3;
     $expected = '012';
     while ($result !== $expected && microtime(true) < $limit) {
         $result .= $process->{$method}();
     }
     $this->assertSame($expected, $result);
     $process->stop();
 }
 public function stopServer()
 {
     $this->process->stop();
 }
コード例 #23
0
ファイル: Server.php プロジェクト: cosmorogers/http-mock
 public function stop($timeout = 10, $signal = null)
 {
     $exitCode = parent::stop($timeout, $signal);
     return $exitCode;
 }
コード例 #24
0
ファイル: DemoServer.php プロジェクト: mihaeu/tarantula
 /**
  * Stops the server.
  */
 public function stopDemoServer()
 {
     $this->demoServerProcess->stop();
 }
コード例 #25
0
ファイル: ProcessTest.php プロジェクト: nervo/symfony
 public function testStop()
 {
     $process = new Process('php -r "while (true) {}"');
     $process->start();
     $this->assertTrue($process->isRunning());
     $process->stop();
     $this->assertFalse($process->isRunning());
     $this->assertTrue($process->hasBeenSignaled());
 }
コード例 #26
0
ファイル: ProcessTest.php プロジェクト: nashadalam/symfony
 public function testStop()
 {
     $process = new Process('php -r "while (true) {}"');
     $process->start();
     $this->assertTrue($process->isRunning());
     $process->stop();
     $this->assertFalse($process->isRunning());
     // skip this check on windows since it does not support signals
     if (!defined('PHP_WINDOWS_VERSION_MAJOR')) {
         $this->assertTrue($process->hasBeenSignaled());
     }
 }
コード例 #27
0
 /**
  * Stop the process and return it's
  * exit code
  *
  * @return int
  */
 public function stop()
 {
     return $this->process->stop();
 }
コード例 #28
0
 /**
  * Stops the process.
  */
 public function stop()
 {
     $this->process->signal(SIGTERM);
     $this->process->stop(3, SIGKILL);
 }
コード例 #29
0
 public function stopServer()
 {
     if ($this->process and $this->process->isRunning()) {
         $this->process->stop(0);
     }
 }
コード例 #30
0
 protected static function stopServer()
 {
     self::$server->stop();
 }