php 获取远程内容,能否只建立一次连接,多次使用.
例如:
$ch = curl_init();
$timeout = 30;
curl_setopt($ch, curlopt_url, $url);
curl_setopt($ch, curlopt_returntransfer, 1);
curl_setopt($ch, curlopt_connecttimeout, $timeout);
curl_setopt($ch, curlopt_followlocation, 1);
$contents = trim(curl_exec($ch));
curl_close($ch);
目标地址的url 是稳定的,仅传递的参数有不同,
能否代码里仅为
$timeout = 30;
curl_setopt($ch, curlopt_url, $url);
curl_setopt($ch, curlopt_returntransfer, 1);
curl_setopt($ch, curlopt_connecttimeout, $timeout);
curl_setopt($ch, curlopt_followlocation, 1);
$contents = trim(curl_exec($ch));
不用每次创立一个连接,和关闭一个连接。
------解决方案--------------------
curlopt_customrequest
------解决方案--------------------
php code[user:root time:14:07:31 path:/home/liangdong/php]$ php file.php http/1.1 200 okdate: thu, 10 may 2012 18:07:32 gmtserver: apache/2.4.1 (unix) php/5.4.0x-powered-by: php/5.4.0set-cookie: phpsessid=qi60b6s1q783a4pnj81rscdet4; path=/expires: thu, 19 nov 1981 08:52:00 gmtcache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0pragma: no-cachecontent-length: 257keep-alive: timeout=5, max=100connection: keep-alivecontent-type: text/html; charset=utf-8^_^ hello,欢迎使用thinkphp
get / http/1.1host: localhostaccept: */*connection:keep-alive[user:root time:14:07:32 path:/home/liangdong/php]$ cat file.php [user:root time:14:07:43 path:/home/liangdong/php]$