当前位置: 首页>>代码示例>>PHP>>正文


PHP Process\PhpProcess类代码示例

本文整理汇总了PHP中Symfony\Component\Process\PhpProcess的典型用法代码示例。如果您正苦于以下问题:PHP PhpProcess类的具体用法?PHP PhpProcess怎么用?PHP PhpProcess使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PhpProcess类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: initServer

function initServer()
{
    $process = new PhpProcess(file_get_contents(__DIR__ . '/worker.php'), __DIR__);
    $process->start();
    sleep(5);
    return $process;
}
开发者ID:crodas,项目名称:worker,代码行数:7,代码来源:bootstrap.php

示例2: handle

 public function handle(GetResponseEvent $event)
 {
     if (null !== $this->securityContext->getToken()) {
         return;
     }
     $request = $event->getRequest();
     if (!$request->hasSession()) {
         throw new \RuntimeException('This authentication method requires a session.');
     }
     $cookies = array_intersect_key($request->cookies->all(), array_flip(array_filter(array_keys($request->cookies->all()), function ($input) {
         return strpos($input, 'wordpress_logged_in_') === 0;
     })));
     $logger = $this->logger;
     if (empty($cookies)) {
         return;
     }
     if (null !== $this->logger) {
         $this->logger->debug('Found eligible cookies prefixed with wordpress_logged_in_');
     }
     $script = call_user_func($this->script, InjectRequestGlobals::toSubprocessGlobals($request), "\$user = wp_get_current_user(); echo json_encode(\$user);");
     $process = new PhpProcess('<?php ' . $script, $this->documentRoot);
     $process->run();
     $output = $process->getOutput();
     $user = json_decode($output);
     // Attempt to load a WordPress user based on cookies for this site's domain.
     if (!$user || isset($user->ID) && $user->ID === 0) {
         return;
     }
     // Translate WordPress roles into Symfony Security component roles.
     $roles = array_map(function ($input) {
         return 'ROLE_WORDPRESS_' . strtoupper($input);
     }, $user->roles);
     $roles[] = 'ROLE_USER';
     // Generate token.
     $token = new WordpressUserToken($roles);
     $token->setUser($user->data->display_name);
     try {
         // Authorize token.
         $authToken = $this->authenticationManager->authenticate($token);
         $this->securityContext->setToken($authToken);
         return;
     } catch (AuthenticationException $failed) {
         // To deny the authentication clear the token. This will redirect to the login page.
         // Make sure to only clear your token, not those of other authentication listeners.
         $token = $this->securityContext->getToken();
         if ($token instanceof WordpressUserToken) {
             $this->securityContext->setToken(null);
         }
         // Deny authentication with a '403 Forbidden' HTTP response
         $response = new Response();
         $response->setStatusCode(403);
         $event->setResponse($response);
     }
     // By default deny authorization
     $response = new Response();
     $response->setStatusCode(403);
     $event->setResponse($response);
 }
开发者ID:bangpound,项目名称:wordpress-silex-extension,代码行数:58,代码来源:WordpressListener.php

示例3: testNonBlockingWorks

    public function testNonBlockingWorks()
    {
        $expected = 'hello world!';
        $process = new PhpProcess(<<<PHP
<?php echo '{$expected}';
PHP
);
        $process->start();
        $process->wait();
        $this->assertEquals($expected, $process->getOutput());
    }
开发者ID:mawaha,项目名称:tracker,代码行数:11,代码来源:PhpProcessTest.php

示例4: testWordpressBootstrap

 public function testWordpressBootstrap()
 {
     $app = $this->createApplication();
     $commandline = realpath('./vendor/wp-cli/wp-cli/bin/wp core config');
     $process = new \Symfony\Component\Process\Process($commandline);
     $process->setWorkingDirectory(realpath('./vendor/wordpress/wordpress'));
     $process->run();
     $output = $process->getOutput();
     $script = $app['php.wordpress36.bootstrap']();
     $process = new \Symfony\Component\Process\PhpProcess('<?php ' . $script, realpath('./vendor/wordpress/wordpress'));
     $process->setWorkingDirectory(realpath('./vendor/wordpress/wordpress'));
     $process->run();
     $output = $process->getOutput();
 }
开发者ID:bangpound,项目名称:php-cms-bootstrap-silex-extension,代码行数:14,代码来源:PhpCmsBootstrapProviderTest.php

示例5: testDrupalBootstrap

 public function testDrupalBootstrap()
 {
     $app = $this->createApplication();
     $commandline = realpath('./vendor/bin/drush');
     $site = md5(microtime());
     $process = new \Symfony\Component\Process\Process($commandline . ' --yes site-install --db-url=sqlite://sites/' . $site . '/files/.ht.sqlite --sites-subdir=' . $site . ' --pipe');
     $process->setWorkingDirectory(realpath('./vendor/drupal/drupal'));
     $process->run();
     $output = $process->getOutput();
     $script = $app['php.drupal7.bootstrap']('http://' . $site . '/index.php', '', 'echo conf_path();');
     $process = new PhpProcess('<?php ' . $script, realpath('./vendor/drupal/drupal'));
     $process->run();
     $output = $process->getOutput();
     $this->assertEquals('sites/' . $site, $output);
 }
开发者ID:bangpound,项目名称:php-cms-bootstrap-silex-extension,代码行数:15,代码来源:PhpCmsBootstrapProviderTest.php

示例6: createProcess

 /**
  * Create process
  */
 protected function createProcess()
 {
     // initialisation du process
     $this->process = new PhpProcess($this->getScript(), $this->getConfiguration()->getCwd(), $this->getConfiguration()->getEnv(), $this->getConfiguration()->getTimeout());
     if ($this->configuration->getParameter('PHP_BINARY')) {
         $this->process->setPhpBinary($this->configuration->getParameter('PHP_BINARY'));
     }
 }
开发者ID:itkg,项目名称:batch,代码行数:11,代码来源:Console.php

示例7: createWorker

 protected function createWorker($id)
 {
     $files = get_included_files();
     if ($_SERVER['PHP_SELF'] != '-') {
         array_shift($files);
     }
     $boostrap = "<?php \n        foreach (" . var_export($files, true) . " as \$file) {\n            require_once \$file;\n        }\n\n        define('__WORKER__', " . var_export($id, true) . ");\n\n        \$config = crodas\\Worker\\Config::import(" . $this->config->export() . ");\n        \$config['worker_id'] = __WORKER__;\n\n        \$server = new crodas\\Worker\\Server(\$config);\n        \$server->worker();\n        ";
     $this->log(null, "Starting process {$id}");
     $process = new PhpProcess($boostrap);
     $process->start();
     $process->id = $id;
     $process->time = time();
     $process->status = empty($args) ? 'idle' : 'busy';
     $process->jobs = 0;
     $process->failed = 0;
     return $process;
 }
开发者ID:crodas,项目名称:worker,代码行数:17,代码来源:Server.php

示例8: assertTranspile

 function assertTranspile($yamlPath)
 {
     $input = new ArrayInput(array());
     $stream = fopen('php://memory', 'rw', false);
     $output = new StreamOutput($stream);
     $symfonyio = new SymfonyIO($input, $output);
     // Load and parse yaml
     $config = Yaml::parse(file_get_contents($yamlPath));
     if (!isset($config['stdout'])) {
         $this->fail('Stdout section not found in $yamlPath');
     }
     if (!isset($config['code'])) {
         $this->fail('Code section not found in $yamlPath');
     }
     // Create temp file for code to transpile
     $tmpPath = tempnam(sys_get_temp_dir(), 'transphpile');
     file_put_contents($tmpPath, "<?php\n" . $config['code']);
     // Transpile code and send to stdout
     $transpiler = new Transpile($symfonyio);
     $transpiler->transpile($tmpPath, '-');
     // unlink tmp file
     unlink($tmpPath);
     // Fetch php5 code written by transpiler
     rewind($stream);
     $php5 = stream_get_contents($stream);
     // Run php5 code
     $process = new PhpProcess($php5);
     $process->run();
     $stdout = $process->getOutput();
     $stderr = $process->getErrorOutput();
     // If we don't define stderr, there should not be any stderr output from our php5 file
     if (!empty($stderr) && !isset($config['stderr'])) {
         $this->fail('Error reported, but no stderr section found in $yamlPath');
     }
     // Check output
     $config['stdout'] = trim($config['stdout']);
     $this->assertRegExp('{' . $config['stdout'] . '}', $stdout, isset($config['name']) ? $config['name'] : "");
     // Check stderr if any
     if (isset($config['stderr'])) {
         $config['stderr'] = trim($config['stderr']);
         if (empty($stderr)) {
             $this->fail('stderr seems empty but should contain an error');
         }
         $this->assertRegExp('{' . $config['stderr'] . '}', $stderr, isset($config['name']) ? $config['name'] : "");
     }
 }
开发者ID:jaytaph,项目名称:Transphpile,代码行数:46,代码来源:FunctionalTestCase.php

示例9: createAndRun

    /**
     * Initiates new actor in a new PHP process
     * @param integer  $id An unique id of an actor, should be free tcp-port in current implementation
     * @param callable $handler
     * @return PhpProcess
     */
    public static function createAndRun($id, callable $handler)
    {
        $serializedHandler = base64_encode((new Serializer())->serialize($handler));
        $autoloadPath = Utils::getAutoloadPath();
        $process = new PhpProcess(<<<EOF
    <?php
        require '{$autoloadPath}';
        \\Phactor\\Phactor\\Actor::initializeChild({$id}, '{$serializedHandler}');
    ?>
EOF
);
        if (null === $process->getCommandLine()) {
            $process->setPhpBinary(PHP_BINARY);
        }
        // workaround for portable windows php
        $process->start();
        return $process;
    }
开发者ID:elnoro,项目名称:phactor,代码行数:24,代码来源:Actor.php

示例10: requestCommand

    /**
     * Submit a frontend request
     *
     * @param string $requestUrl URL to make a frontend request
     */
    public function requestCommand($requestUrl)
    {
        // TODO: this needs heavy cleanup!
        $template = file_get_contents(PATH_typo3 . 'sysext/core/Tests/Functional/Fixtures/Frontend/request.tpl');
        $arguments = array('documentRoot' => PATH_site, 'requestUrl' => $requestUrl);
        // No other solution atm than to fake a CLI request type
        $code = '<?php
		define(\'TYPO3_REQUESTTYPE\', 6);
		?>';
        $code .= str_replace(array('{originalRoot}', '{arguments}'), array(PATH_site, var_export($arguments, true)), $template);
        $process = new PhpProcess($code);
        $process->mustRun();
        $rawResponse = json_decode($process->getOutput());
        if ($rawResponse === NULL || $rawResponse->status === Response::STATUS_Failure) {
            $this->outputLine('<error>An error occurred while trying to request the specified URL.</error>');
            $this->outputLine(sprintf('<error>Error: %s</error>', !empty($rawResponse->error) ? $rawResponse->error : 'Could not decode response. Please check your error log!'));
            $this->outputLine(sprintf('<error>Content: %s</error>', $process->getOutput()));
            $this->sendAndExit(1);
        }
        $this->output($rawResponse->content);
    }
开发者ID:Outdoorsman,项目名称:typo3_console,代码行数:26,代码来源:FrontendCommandController.php

示例11: execute

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        /** @var FormatterHelper $formatter */
        $formatter = $this->getHelper('formatter');
        //        $process = new Process('wkhtmltopdf http://google.com/ test.pdf');
        //        $process->run();
        //        $process->stop(3, SIGINT);
        //        $process->mustRun(function ($type, $message) use ($output, $formatter) {
        //            if ($type === Process::ERR) {
        //                $output->writeln($formatter->formatBlock($message, 'error'));
        //            } else {
        //                $output->writeln($formatter->formatBlock($message, 'comment'));
        //            }
        //        });
        $process = new PhpProcess(<<<EOF
        <?php
            sleep(5);
            echo "OK
";
        ?>
EOF
);
        $process->start();
        $process->stop(2, SIGINT);
        if (!$process->isSuccessful()) {
            $output->writeln($formatter->formatBlock($process->getErrorOutput(), 'error', true));
            return;
        }
        $output->writeln($formatter->formatSection('success', $process->getOutput()));
    }
开发者ID:GrizliK1988,项目名称:symfony-certification-prepare-project,代码行数:30,代码来源:ProcessCommand.php

示例12: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $filename = $input->getArgument('filename');
     if (null !== $filename) {
         $filename = $this->getSnippetsPath() . DIRECTORY_SEPARATOR . $filename;
         if (!file_exists($filename)) {
             throw new InvalidArgumentException(sprintf('file "%s" does not exist', $filename));
         }
         $snippets = array(new \SplFileInfo($filename));
         $nbSnippets = 1;
     } else {
         $snippets = $this->listSnippets(new Finder());
         $nbSnippets = count($snippets->getIterator()->getIterator());
     }
     $dialog = $this->getHelperSet()->get('dialog');
     $i = 0;
     foreach ($snippets as $snippet) {
         $snippetCode = file_get_contents($snippet->getRealpath());
         $output->writeln(sprintf('<info>DEMO [%d/%d]:</info> %s', $i + 1, $nbSnippets, $snippet->getRealPath()));
         $this->hr($output, 20);
         $output->writeln('<info>CODE :</info>');
         $output->writeln($snippetCode);
         $this->hr($output, 20);
         $dialog->askConfirmation($output, '<question>Press enter to see result</question>');
         $output->writeln('<info>RESULT :</info>');
         $process = new PhpProcess($snippetCode);
         $process->run();
         if (!$process->isSuccessful()) {
             $output->writeln(array('<error>Error ::</error>', $process->getErrorOutput()));
         }
         $output->writeln(array('<comment>Output ::</comment>', $process->getOutput()));
         $this->hr($output);
         $i++;
         if ($i < $nbSnippets) {
             $dialog->askConfirmation($output, '<question>Press enter to continue</question>');
             $output->writeln("[2J");
         }
     }
 }
开发者ID:ruian,项目名称:demoer,代码行数:39,代码来源:runCommand.php

示例13: testCommandLine

    public function testCommandLine()
    {
        $process = new PhpProcess(<<<'PHP'
<?php echo 'foobar';
PHP
);
        $commandLine = $process->getCommandLine();
        $f = new PhpExecutableFinder();
        $this->assertContains($f->find(), $commandLine, '::getCommandLine() returns the command line of PHP before start');
        $process->start();
        $this->assertContains($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP after start');
        $process->wait();
        $this->assertContains($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP after wait');
    }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:14,代码来源:PhpProcessTest.php

示例14: testCommandLine

    public function testCommandLine()
    {
        if ('phpdbg' === PHP_SAPI) {
            $this->markTestSkipped('phpdbg SAPI is not supported by this test.');
        }
        $process = new PhpProcess(<<<PHP
<?php echo 'foobar';
PHP
);
        $f = new PhpExecutableFinder();
        $commandLine = $f->find();
        $this->assertSame($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP before start');
        $process->start();
        $this->assertSame($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP after start');
        $process->wait();
        $this->assertSame($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP after wait');
    }
开发者ID:nix9,项目名称:laracasts,代码行数:17,代码来源:PhpProcessTest.php

示例15: doRequestInProcess

 /**
  * Makes a request in another process.
  *
  * @param object $request An origin request instance
  *
  * @return object An origin response instance
  *
  * @throws \RuntimeException When processing returns exit code
  */
 protected function doRequestInProcess($request)
 {
     // We set the TMPDIR (for Macs) and TEMP (for Windows), because on these platforms the temp directory changes based on the user.
     $process = new PhpProcess($this->getScript($request), null, array('TMPDIR' => sys_get_temp_dir(), 'TEMP' => sys_get_temp_dir()));
     $process->run();
     if (!$process->isSuccessful() || !preg_match('/^O\\:\\d+\\:/', $process->getOutput())) {
         throw new \RuntimeException(sprintf('OUTPUT: %s ERROR OUTPUT: %s', $process->getOutput(), $process->getErrorOutput()));
     }
     return unserialize($process->getOutput());
 }
开发者ID:hichammoad,项目名称:symfony,代码行数:19,代码来源:Client.php


注:本文中的Symfony\Component\Process\PhpProcess类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。