我想将 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);