/**
* curl的GET方式获取数据
* @param $url
*/
public static function getCurl($url, $outTime = 60)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_TIMEOUT, $outTime);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
/**
* curl的POST保持长连接方式获取数据,
* @param $url
*/
public static function keepAliveCurl($url, $param)
{
$post = array ();
if ($param) {
foreach ($param as $key => $value ) {
if ($value != '') {
$post[] = urlencode($key) . '=' . urlencode($value);
}
}
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
$header = array ('Connection: Keep-Alive');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_USERAGENT, 'Quote_Requester');
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, implode('&', $post));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
* curl的GET方式获取数据
* @param $url
*/
public static function getCurl($url, $outTime = 60)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_TIMEOUT, $outTime);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
/**
* curl的POST保持长连接方式获取数据,
* @param $url
*/
public static function keepAliveCurl($url, $param)
{
$post = array ();
if ($param) {
foreach ($param as $key => $value ) {
if ($value != '') {
$post[] = urlencode($key) . '=' . urlencode($value);
}
}
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
$header = array ('Connection: Keep-Alive');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_USERAGENT, 'Quote_Requester');
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, implode('&', $post));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}