php多进程实现

项目中用到发送短信,但是单进程发送效果不是很好,所以考虑多进程,所以记录下以便温习!


        if (!function_exists('pcntl_fork')) {
            die('pcntl_fork is not exist');
        }
        for ($i = 0; $i < 10; $i++) {
            $pid = pcntl_fork();
            if ($pid == -1) {
                echo 'could not fork';
                continue;
            } else if ($pid) {
                pcntl_wait($status);
            } else {
                $index_path = SITE_PATH . 'index.php';
                $php_path = C('PHP_PATH');
                $key = $this->key . $orderId;
                echo exec("{$php_path} {$index_path} .路径. &>> /日志.log &");
                exit(0);
            }
        }

这就是多进程,在日志文件里可以看到如下:



猜你喜欢

转载自blog.csdn.net/qq_32936067/article/details/64128841
今日推荐