• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP pcntl_exec函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: exec

 /**
  * Exec
  *
  * @param string $path The path to a binary executable or a script with a valid path pointing to an executable in the shebang
  * @param array  $args Array of argument strings passed to the program.
  * @param array  $envs Array of strings which are passed as environment to the program
  *
  * @return null|bool Returns FALSE on error and does not return on success.
  */
 public function exec($path, array $args = array(), array $envs = array())
 {
     return pcntl_exec($path, $args, $envs);
 }
开发者ID:dantudor,项目名称:pcntl,代码行数:13,代码来源:Pcntl.php


示例17: update_main

function update_main()
{
    global $argc, $argv;
    global $gbl, $sgbl, $login, $ghtml;
    debug_for_backend();
    $prognameNice = $sgbl->__var_program_name_nice;
    $login = new Client(null, null, 'upgrade');
    $opt = parse_opt($argv);
    print "Getting Version Info from the Server...\n";
    print "Connecting... Please wait....\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';
    }
    $thisversion = $sgbl->__ver_major_minor_release;
    if ($upversion) {
        do_upgrade($upversion);
        print "Upgrade Done!\nStarting the Cleanup.\n";
        flush();
    } else {
        print "{$prognameNice} is the latest version ({$thisversion})\n";
        print "Run 'sh /script/cleanup' if you want restore/fix possible issues.\n";
        exit;
    }
    if (is_running_secondary()) {
        print "Not running the Update Cleanup, because this server is a secondary.\n";
        exit;
    }
    // Needs to be here. So any php.ini change takes immediately effect.
    print "Copy Core PHP.ini\n";
    lxfile_cp("htmllib/filecore/php.ini", "/usr/local/lxlabs/ext/php/etc/php.ini");
    pcntl_exec("/bin/sh", array("../bin/common/updatecleanup-core.sh", "--type={$type}"));
    print "{$prognameNice} is Ready!\n\n";
}
开发者ID:hypervm-ng,项目名称:hypervm-ng,代码行数:39,代码来源:updatelib.php


示例18: shellpcntl

function shellpcntl($cmd)
{
    if (!function_exists('pcntl_exec')) {
        return false;
    }
    $args = explode(' ', $cmd);
    $path = $args[0];
    unset($args[0]);
    if (pcntl_exec($path, $args) === false) {
        return false;
    } else {
        return 'El comando fue ejecutado, pero no se pudo recuperar la salida';
    }
}
开发者ID:laiello,项目名称:emelco,代码行数:14,代码来源:emelco-1.3.php


示例19: restart

 public function restart()
 {
     $serialized = serialize($this);
     $file = realpath(__DIR__ . "/../../bin/gearman_restart");
     $serializedFile = sys_get_temp_dir() . '/gearman_restart_' . uniqid();
     file_put_contents($serializedFile, $serialized);
     if ($file && is_executable($file)) {
         pcntl_exec($file, ['serialized' => $serializedFile]);
         exit;
     } elseif ($file) {
         $dir = dirname($file);
         $content = file_get_contents($dir . '/gearman_restart_template');
         $content = str_replace('%path', $dir . '/gearman_restart.php', $content);
         $newFile = sys_get_temp_dir() . '/gearman_restart_' . uniqid();
         file_put_contents($newFile, $content);
         chmod($newFile, 0755);
         pcntl_exec($newFile, ['serialized' => $serializedFile]);
         unlink($newFile);
         exit;
     }
 }
开发者ID:ly827,项目名称:gearman,代码行数:21,代码来源:Application.php


示例20: socket_shutdown

    global $sock, $db;
    echo "\n\nctrl-c or kill signal received. Tidying up ... ";
    socket_shutdown($sock, 0);
    socket_close($sock);
    $db = null;
    die("Bye!\n");
});
pcntl_signal_dispatch();
// let's try and connect
echo "Listen to acarsdec ... ";
// create our socket and set it to non-blocking
$sock = socket_create(AF_INET, SOCK_DGRAM, 0) or die("Unable to create socket\n");
// Bind the source address
if (!socket_bind($sock, $globalACARSHost, $globalACARSPort)) {
    $errorcode = socket_last_error();
    $errormsg = socket_strerror($errorcode);
    die("Could not bind socket : [{$errorcode}] {$errormsg} \n");
}
echo "LISTEN UDP MODE \n\n";
while (1) {
    $r = socket_recvfrom($sock, $buffer, 512, 0, $remote_ip, $remote_port);
    // lets play nice and handle signals such as ctrl-c/kill properly
    pcntl_signal_dispatch();
    $dataFound = false;
    //  (null) 2 23/02/2015 14:46:06 0 -16 X .D-AIPW ! 1L 7 M82A LH077P 010952342854:VP-MIBI+W+0)-V+(),GB1
    $ACARS::add(trim($buffer));
    socket_sendto($sock, "OK " . $buffer, 100, 0, $remote_ip, $remote_port);
    $ACARS::deleteLiveAcarsData();
}
pcntl_exec($_, $argv);
开发者ID:hzmarrou,项目名称:FlightAirMap,代码行数:30,代码来源:daemon-acars.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP pcntl_fork函数代码示例发布时间:2022-05-15
下一篇:
PHP pcntl_alarm函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap