drk7700 2018-02-04 18:55
浏览 99

使用php curl在后台运行脚本

I want to run a function as background process using curl. Below is my code.

  foreach ($iles $file=> $size) {

                $params ="file=$file&fullpath=$fullpath&minWidth=$minWidth";
                $url = 'http://test.rul.com/file/listFiles?'.$params;
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
                $curled=curl_exec($ch);
                curl_close($ch);
            }
        }


     public function getlistFiles() {
 $fullpath = $_REQUEST['fullpath'];
 }

but this curl is not running on background. how can I execute this as background ?

  • 写回答

1条回答 默认 最新

  • dongyin2390 2018-02-04 19:18
    关注

    Here is an example for the calling script with curl:

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_TIMEOUT_MS, 400); 
    curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
    $response = curl_exec($ch);
    curl_close($ch);
    

    2nd script

    ignore_user_abort(true);
    usleep(500000);    // wait 500ms
    // do stuff
    

    Note that you will always get a curl error CURLE_OPERATION_TIMEDOUT, which can be ignored.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器