【问题标题】:Running script in background using php curl使用 php curl 在后台运行脚本
【发布时间】:2018-02-04 18:55:06
【问题描述】:

我想使用 curl 作为后台进程运行一个函数。下面是我的代码。

  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'];
 }

但是这个 curl 没有在后台运行。我怎样才能将其作为后台执行?

【问题讨论】:

标签: php curl background-process


【解决方案1】:

以下是使用 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);

第二个脚本

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

请注意,您总是会收到 curl 错误CURLE_OPERATION_TIMEDOUT,可以忽略。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    相关资源
    最近更新 更多