PHP-CLI多进程

  1. 作者QQ:67065435 QQ群:821635552

  2. 本站内容全部为作者原创,转载请注明出处!

  3. 安装PHP扩展:pcntl

  4. PHP源码

    <?php
    /**
     * 假设要执行命令
     * /usr/local/php7/bin/php /www/xxx.php --option 12345
     * /usr/local/php7/bin/php /www/xxx.php --option 12346
     * /usr/local/php7/bin/php /www/xxx.php --option 12347
     */
    $arr = [
        12345,
        12346,
        12347
    ];
    $exec_file = "/usr/local/php7/bin/php";
    foreach ($arr as $val) {
        $pid = pcntl_fork();
        if ($pid == -1) {
            exit(0);
        } elseif ($pid) {
            pcntl_wait($status, WNOHANG);
        } else {
            $command = ["/www/xxx.php", "--option", $val];
            pcntl_exec($exec_file, $command);
            exit(0);
        }
    }
    exit(0);
    
Copyright © 豆包嘿嘿~ 2012-∞ 冀ICP备17033181号 all right reserved,powered by Gitbook修订: 2020-08-19 14:05:41

results matching ""

    No results matching ""