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


PHP pcntl_exec函数代码示例

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


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

示例1: scryed

 protected function scryed($total, $workers = 8, array $args)
 {
     $quiet = $this->option('quiet');
     $pids = [];
     for ($i = 0; $i < $workers; $i++) {
         $pids[$i] = pcntl_fork();
         switch ($pids[$i]) {
             case -1:
                 echo "fork error : {$i} \r\n";
                 exit;
             case 0:
                 $limit = floor($total / $workers);
                 $offset = $i * $limit;
                 if ($i == $workers - 1) {
                     $limit = $total - $offset;
                 }
                 $this->info(">>> 一个子进程已开启  |   剩 " . ($workers - $i - 1) . " 个  |  pid = " . getmypid() . " | --limit = {$limit}  |  --offset = {$offset}");
                 sleep(2);
                 // 这个sleep仅为看清上面的info,可删
                 array_push($args, "--limit={$limit}", "--offset={$offset}");
                 $quiet && array_push($args, '--quiet');
                 pcntl_exec('/usr/bin/php', $args, []);
                 // exec("/usr/bin/php5 artisan crawler:model autohome --sych-model=false --offset={$offset} --limit={$limit}");
                 // pcntl_exec 与 exec 同样可以执行命令。区别是exec 不会主动输出到shell控制台中
                 exit;
             default:
                 break;
         }
     }
     foreach ($pids as $pid) {
         $pid && pcntl_waitpid($pid, $status);
     }
 }
开发者ID:leebivip,项目名称:dns,代码行数:33,代码来源:Boot.php

示例2: pleac_Gathering_Output_from_a_Program

function pleac_Gathering_Output_from_a_Program()
{
    // Run a command and return its results as a string.
    $output_string = shell_exec('program args');
    // Same as above, using backtick operator.
    $output_string = `program args`;
    // Run a command and return its results as a list of strings,
    // one per line.
    $output_lines = array();
    exec('program args', $output_lines);
    // -----------------------------
    // The only way to execute a program without using the shell is to
    // use pcntl_exec(). However, there is no way to do redirection, so
    // you can't capture its output.
    $pid = pcntl_fork();
    if ($pid == -1) {
        die('cannot fork');
    } elseif ($pid) {
        pcntl_waitpid($pid, $status);
    } else {
        // Note that pcntl_exec() automatically prepends the program name
        // to the array of arguments; the program name cannot be spoofed.
        pcntl_exec($program, array($arg1, $arg2));
    }
}
开发者ID:tokenrove,项目名称:pfff,代码行数:25,代码来源:Gathering_Output_from_a_Program.php

示例3: update_main

function update_main()
{
    global $argc, $argv;
    global $gbl, $sgbl, $login, $ghtml;
    debug_for_backend();
    $program = $sgbl->__var_program_name;
    $login = new Client(null, null, 'upgrade');
    $opt = parse_opt($argv);
    print "Getting Version Info from the Server...\n";
    if (isset($opt['till-version']) && $opt['till-version'] || lxfile_exists("__path_slave_db")) {
        $sgbl->slave = true;
        $upversion = findNextVersion($opt['till-version']);
        $type = 'slave';
    } else {
        $sgbl->slave = false;
        $upversion = findNextVersion();
        $type = 'master';
    }
    print "Connecting... Please wait....\n";
    if ($upversion) {
        do_upgrade($upversion);
        print "Upgrade Done.. Executing Cleanup....\n";
        flush();
    } else {
        print "{$program} is the latest version\n";
    }
    if (is_running_secondary()) {
        print "Not running Update Cleanup, because this is running secondary \n";
        exit;
    }
    lxfile_cp("htmllib/filecore/php.ini", "/usr/local/lxlabs/ext/php/etc/php.ini");
    $res = pcntl_exec("/bin/sh", array("../bin/common/updatecleanup.sh", "--type={$type}"));
    print "Done......\n";
}
开发者ID:lonelywoolf,项目名称:hypervm,代码行数:34,代码来源:updatelib.php

示例4: pleac_Replacing_the_Current_Program_with_a_Different_One

function pleac_Replacing_the_Current_Program_with_a_Different_One()
{
    // Transfer control to the shell to run another program.
    pcntl_exec('/bin/sh', array('-c', 'archive *.data'));
    // Transfer control directly to another program.
    pcntl_exec('/path/to/archive', array('accounting.data'));
}
开发者ID:Halfnhav4,项目名称:pfff,代码行数:7,代码来源:Replacing_the_Current_Program_with_a_Different_One.php

示例5: restart

/**
 * Restarts the current server
 * Only works on Linux (not MacOS and Windows)
 * 
 * @return void
 */
function restart()
{
    if (!function_exists("pcntl_exec")) {
        return;
    }
    global $handler;
    fclose($handler->getServer()->__socket);
    pcntl_exec($_SERVER["_"], $_SERVER["argv"]);
}
开发者ID:fbone,项目名称:mediboard4,代码行数:15,代码来源:socket_server.php

示例6: pleac_Running_Another_Program

function pleac_Running_Another_Program()
{
    // Run a simple command and retrieve its result code.
    exec("vi {$myfile}", $output, $result_code);
    // -----------------------------
    // Use the shell to perform redirection.
    exec('cmd1 args | cmd2 | cmd3 >outfile');
    exec('cmd args <infile >outfile 2>errfile');
    // -----------------------------
    // Run a command, handling its result code or signal.
    $pid = pcntl_fork();
    if ($pid == -1) {
        die('cannot fork');
    } elseif ($pid) {
        pcntl_waitpid($pid, $status);
        if (pcntl_wifexited($status)) {
            $status = pcntl_wexitstatus($status);
            echo "program exited with status {$status}\n";
        } elseif (pcntl_wifsignaled($status)) {
            $signal = pcntl_wtermsig($status);
            echo "program killed by signal {$signal}\n";
        } elseif (pcntl_wifstopped($status)) {
            $signal = pcntl_wstopsig($status);
            echo "program stopped by signal {$signal}\n";
        }
    } else {
        pcntl_exec($program, $args);
    }
    // -----------------------------
    // Run a command while blocking interrupt signals.
    $pid = pcntl_fork();
    if ($pid == -1) {
        die('cannot fork');
    } elseif ($pid) {
        // parent catches INT and berates user
        declare (ticks=1);
        function handle_sigint($signal)
        {
            echo "Tsk tsk, no process interruptus\n";
        }
        pcntl_signal(SIGINT, 'handle_sigint');
        while (!pcntl_waitpid($pid, $status, WNOHANG)) {
        }
    } else {
        // child ignores INT and does its thing
        pcntl_signal(SIGINT, SIG_IGN);
        pcntl_exec('/bin/sleep', array('10'));
    }
    // -----------------------------
    // Since there is no direct access to execv() and friends, and
    // pcntl_exec() won't let us supply an alternate program name
    // in the argument list, there is no way to run a command with
    // a different name in the process table.
}
开发者ID:Halfnhav4,项目名称:pfff,代码行数:54,代码来源:Running_Another_Program.php

示例7: cli_edit

function cli_edit($post)
{
    if ($editor = $GLOBALS['EDITOR']) {
    } else {
        if ($editor = getenv('EDITOR')) {
        } else {
            $editor = "vi";
        }
    }
    $command = rtrim(`which {$editor}`);
    if ($command) {
        pcntl_exec($command, array($post), $_ENV);
    }
}
开发者ID:rcrowley,项目名称:bashpress,代码行数:14,代码来源:lib_cli.php

示例8: execute

 public function execute()
 {
     while (@ob_end_flush()) {
     }
     $php = $_SERVER['_'];
     $host = $this->options->host ?: 'localhost';
     $port = $this->options->port ?: '8000';
     chdir(PH_APP_ROOT . DIRECTORY_SEPARATOR . 'webroot');
     if (extension_loaded('pcntl')) {
         pcntl_exec($php, array('-S', "{$host}:{$port}", 'index.php'));
     } else {
         $this->logger->info("Starting server at http://{$host}:{$port}");
         passthru($php . ' ' . join(' ', array('-S', "{$host}:{$port}", 'index.php')));
     }
 }
开发者ID:corneltek,项目名称:phifty,代码行数:15,代码来源:ServerCommand.php

示例9: spawn

 public function spawn($path, $args = [], $envs = [])
 {
     $ret = false;
     $pid = $this->fork();
     if (0 === $pid) {
         if (false === pcntl_exec($path, $args, $envs)) {
             exit(0);
         }
     } elseif ($pid > 0) {
         $ret = $pid;
     } else {
         // nothing to do ...
     }
     return $ret;
 }
开发者ID:wedgwood,项目名称:serverbench.php,代码行数:15,代码来源:Pool.php

示例10: shutDownCallback

 protected function shutDownCallback()
 {
     $_ = $_SERVER['_'];
     return function () use($_) {
         global $argv;
         $argvLocal = $argv;
         array_shift($argvLocal);
         // @codeCoverageIgnoreStart
         if (!defined('UNIT_TESTING')) {
             pcntl_exec($_, $argvLocal);
         }
         // @codeCoverageIgnoreEnd
         return;
     };
 }
开发者ID:dubpub,项目名称:robo-reset,代码行数:15,代码来源:RoboResetTrait.php

示例11: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $userInteraction = new ConsoleUserInteraction($input, $output);
     $processRunner = new InteractiveProcessRunner($userInteraction);
     if (!$this->inHomeDirectory()) {
         $output->writeln('<error>The project have to be in your home directly to be able to share it with the Docker VM</error>');
         return 1;
     }
     try {
         $dockerComposePath = $this->getDockerComposePath($processRunner);
         pcntl_exec($dockerComposePath, ['up']);
         return 0;
     } catch (ProcessFailedException $e) {
         return 1;
     }
 }
开发者ID:richardmiller,项目名称:dock-cli,代码行数:19,代码来源:UpCommand.php

示例12: launch

 function launch()
 {
     $this->concentrator_pid = pcntl_fork();
     if ($this->concentrator_pid == -1) {
         $errno = posix_get_last_error();
         throw new Exception("Error forking off mysql concentrator: {$errno}: " . posix_strerror($errno) . "\n");
     } elseif ($this->concentrator_pid == 0) {
         $cmd = "/usr/bin/php";
         $args = array("{$this->bin_path}", "-h", $this->settings['host'], '-p', $this->settings['port']);
         if (array_key_exists('listen_port', $this->settings)) {
             $args[] = '-l';
             $args[] = $this->settings['listen_port'];
         }
         chdir(dirname(__FILE__));
         pcntl_exec("/usr/bin/php", $args);
         throw new Exception("Error executing '{$cmd} " . implode(" ", $args) . "'");
     }
 }
开发者ID:giant-rabbit,项目名称:mysql-concentrator,代码行数:18,代码来源:Launcher.php

示例13: coerceWritable

 public function coerceWritable($wait = 1)
 {
     try {
         $this->assertWritable();
     } catch (UnexpectedValueException $e) {
         if (!function_exists('pcntl_exec')) {
             $this->log('<error>' . $e->getMessage() . '</error>');
             return;
         }
         $this->log('<info>' . $e->getMessage() . ', trying to re-spawn with correct config</info>');
         if ($wait) {
             sleep($wait);
         }
         $args = array_merge(array('php', '-d phar.readonly=off'), $_SERVER['argv']);
         if (pcntl_exec('/usr/bin/env', $args) === false) {
             $this->log('<error>Unable to switch into new configuration</error>');
             return;
         }
     }
 }
开发者ID:Grisou13,项目名称:phar-composer,代码行数:20,代码来源:Packager.php

示例14: test02

 /**
  * Test that the table is actually locked.
  */
 public function test02()
 {
     $application = new Application();
     $application->add(new AuditCommand());
     // Start process that inserts rows into TABLE1.
     $pid = pcntl_fork();
     if ($pid == 0) {
         // Child process.
         pcntl_exec(__DIR__ . '/config/generator.php');
     }
     // Parent process.
     sleep(2);
     /** @var AuditCommand $command */
     $command = $application->find('audit');
     $command->setRewriteConfigFile(false);
     $commandTester = new CommandTester($command);
     $commandTester->execute(['command' => $command->getName(), 'config file' => __DIR__ . '/config/audit.json']);
     // Tell the generator it is time to stop.
     posix_kill($pid, SIGUSR1);
     $status = $commandTester->getStatusCode();
     $this->assertSame(0, $status, 'status code');
     pcntl_waitpid($pid, $status);
     $this->assertEquals(0, $status);
     // Reconnect to DB.
     StaticDataLayer::connect('localhost', 'test', 'test', self::$dataSchema);
     // It can take some time before that all rows generated by $generator are visible by this process.
     $n1 = 0;
     $n2 = 0;
     sleep(5);
     for ($i = 0; $i < 60; $i++) {
         $n1 = StaticDataLayer::executeSingleton1("select AUTO_INCREMENT - 1 \n                                                from information_schema.TABLES\n                                                where TABLE_SCHEMA = 'test_data'\n                                                and   TABLE_NAME   = 'TABLE1'");
         $n2 = StaticDataLayer::executeSingleton1('select count(*) from test_audit.TABLE1');
         if (4 * $n1 == $n2) {
             break;
         }
         sleep(3);
     }
     $this->assertEquals(4 * $n1, $n2, 'count');
 }
开发者ID:setbased,项目名称:php-audit,代码行数:42,代码来源:LockTableTestCase.php

示例15: pcntl_exec

<?php

pcntl_exec("/bin/sh", array(__DIR__ . "/test_pcntl_exec.sh"), array("name" => "value"));
开发者ID:badlamer,项目名称:hhvm,代码行数:3,代码来源:pcntl_exec.php


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