代码之家  ›  专栏  ›  技术社区  ›  Ozzy

php同时启动执行文件

  •  0
  • Ozzy  · 技术社区  · 15 年前

    基本上,我是在用apache bench做一些测试。我正在测试的文件需要2秒执行(经过优化,它连接到外部服务器,因此速度减慢)

    基本上,我发现我模拟的并发用户越多,每秒可以执行的文件就越多。

    我能用php做这样的事情吗?:

    <?php
    
    execute_file('file.php');
    execute_file('file.php');
    execute_file('file.php');
    execute_file('file.php');
    execute_file('file.php');
    
    ?>
    

    这将执行文件5次,但不会等待文件完成下载,因此上面的示例将快速调用5个函数,然后退出。

    我假设会使用某种超时?

    3 回复  |  直到 8 年前
        1
  •  0
  •   Alexey Shokov    8 年前

    也许是那样的?

    function execute_file($file) {
        $pid = pcntl_fork();
        if ($pid === 0) {
            exec("php $file");
        }
    }
    
        2
  •  0
  •   Sarfraz    15 年前

    怎么样?

    exec('file.php');
    
        3
  •  0
  •   cosy    15 年前

    exec('file.php');