我想将curl_multi_exec记录存储到变量中,但是在使用CURLOPT_RETURNTRANSFER = TRUE之后它对我来说没有用,然后我做了一些研究并添加了curl_multi_getcontent这很好用我的意思是它的变量的记录值但问题是它只在变量中存储很少的结果。
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $stream_url,
CURLOPT_ENCODING => "gzip",
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_TIMEOUT => 10,
CURLOPT_USERPWD => $user.":".$pass,
CURLOPT_WRITEFUNCTION => "print_out_data",
//CURLOPT_RETURNTRANSFER => true,
CURLOPT_VERBOSE => true // uncomment for curl verbosity
));
$running = null;
$mh = curl_multi_init();
curl_multi_add_handle($mh, $ch);
do {
curl_multi_select($mh, 1);
curl_multi_exec($mh, $running);
$content = curl_multi_getcontent($ch);
$arr = json_decode($content, true);
// print_r($arr);
$foo = $arr['id'];
$bar = $arr['body'];
} while($running > 0);
curl_multi_remove_handle($mh, $ch);
curl_multi_close($ch);
答案 0 :(得分:2)
在做{}之前()写
$content = array();
行
$content = curl_multi_getcontent($ch);
替换为
$content[] = curl_multi_getcontent($ch);
循环写入后
print_r($content);