使用php curl在后台运行脚本 [英] Running script in background using php curl
本文介绍了使用php curl在后台运行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用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 ?
推荐答案
以下是带有curl的调用脚本的示例:
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);
第二个脚本
ignore_user_abort(true);
usleep(500000); // wait 500ms
// do stuff
请注意,您总是会收到卷曲错误CURLE_OPERATION_TIMEDOUT
,该错误可以忽略.
Note that you will always get a curl error CURLE_OPERATION_TIMEDOUT
, which can be ignored.
这篇关于使用php curl在后台运行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文