【问题标题】:PHP Launch Execute Files ConcurrentlyPHP 启动并发执行文件
【发布时间】:2010-04-24 09:49:59
【问题描述】:

基本上,我正在使用 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 个函数然后退出。

我假设会使用某种超时?

【问题讨论】:

    标签: php download timeout


    【解决方案1】:

    也许是这样的?

    function execute_file($file) {
        $pid = pcntl_fork();
        if ($pid === 0) {
            exec("php $file");
        }
    }
    

    【讨论】:

      【解决方案2】:

      怎么样?

      exec('file.php');
      

      【讨论】:

        【解决方案3】:

        exec('file.php');

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-12-24
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2010-10-02
          • 1970-01-01
          相关资源
          最近更新 更多