curl_multi_getcontent返回空字符串 [英] curl_multi_getcontent returns empty string
问题描述
这个问题与 PHP curl_multi_gecontent返回null 非常相似,但是我在那里找不到解决方案。如果尝试回显应包含请求响应的函数结果,则会得到一个空字符串()。
This question is very similar to PHP curl_multi_gecontent returns null, but I could not find a solution there. If I try to echo the result of the function, which should contain the request response, I get an empty string ("") instead.
我肯定错了什么地方在我的代码中,但我无法动弹。有人可以帮忙吗?
Surely I am missing something wrong in my code but I can't put my finger on it. Can anyone help?
$id = "stuff";
$password = "mcmuffin";
$data = json_decode(file_get_contents('php://input'), true);
$ch = array();
// build the individual requests, but do not execute them
for($i = 0; $i < sizeof($data); $i++){
$searchText = $data[$i];
$type = "ligne3;pdi;voie;commune;cedexa";
$word = "Contient";
$option = "AND_OR_RES";
$format = "json";
$url = "http://somewebservice/service?chaineRecherche=".urlencode($searchText)."&typeRecherche=".urlencode($type)."&optionMot=".urlencode($word)."&optionRecherche=".urlencode($option)."&typeResultat=".urlencode($format)."&idClient=".urlencode($id)."&passwdClient=".urlencode($mcmuffin);
$currentCurl = curl_init($url);
curl_setopt($currentCurl, CURLOPT_HEADER, 0);
curl_setopt($currentCurl, CURLOPT_RETURNTRANSFER, true);
array_push($ch, $currentCurl);
}
// build the multi-curl handle, adding all $ch
$mh = curl_multi_init();
for($i = 0; $i < sizeof($ch); $i++){
curl_multi_add_handle($mh, $ch[$i]);
}
// execute all queries simultaneously, and continue when all are complete
$active = null;
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
// all of our requests are done, we can now access the results
for($i = 0; $i < sizeof($ch); $i++){
echo "bonjour"; //does output
$response = curl_multi_getcontent($ch[$i]); //empty??
echo json_encode($response);
}
//close the handles
for($i = 0; $i < sizeof($ch); $i++){
curl_multi_remove_handle($mh, $ch[$i]);
}
curl_multi_close($mh);
谢谢
推荐答案
这是一个代理问题。此cURL选项可解决此问题。
It was a proxy issue. This cURL option fixes the problem.
curl_setopt($ ch,CURLOPT_PROXY,'proxy url');
在附近网络上同事的计算机上,我们收到了代理拒绝而不是空字符串。我的计算机将收到一个空字符串而不是代理消息的原因将永远是个谜。
On a colleague's computer on a nearby network we received the proxy rejectal instead of an empty string. The reason why my computer would receive an empty string instead of the proxy message will forever remain a mystery.
这篇关于curl_multi_getcontent返回空字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!