first composer require guzzlehttp/guzzle
use GuzzleHttp\Client;
function curl_get($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
function guzzle_get($url)
{
$client = new Client();
try {
$tmp = $client->get($url,array("timeout"=>3,"connect_timeout"=>3));
$res = strval($tmp->getBody());
} catch (\Exception $e) {
$res = "";
}
return $res;
}
$res = guzzle_get("http://i.hq.sinajs.cn/?list=sh600011,sh600012");
// var hq_str_sh600011%2Csh600012="";\n
$res = curl_get("http://i.hq.sinajs.cn/?list=sh600011,sh600012");
// var hq_str_sh600011=",7.620,7.630,7.570,7.840,7.480,7.570,7.580,24252178,185351517.000,17372,7.570,65100,7.560,47600,7.550,19200,7.540,43200,7.530,31900,7.580,3300,7.590,46800,7.600,57580,7.610,9000,7.620,2018-09-19,15:00:00,00";var hq_str_sh600012=",5.490,5.500,5.570,5.610,5.470,5.560,5.570,3832663,21267001.000,89200,5.560,60100,5.550,32800,5.540,14500,5.530,29200,5.520,32328,5.570,74300,5.580,129500,5.590,114700,5.600,93300,5.610,2018-09-19,15:00:00,00";
what"s the difference between the two, and why does guzzle return an error?