Php can establish a connection only once to obtain remote content and use it multiple times. example: & nbsp; $ chcurl_init (); & nbsp; $ timeout30; & nbsp; curl_setopt ($ ch, CURLOPT_URL, $ url); & nbsp; curl_setopt ($ ch, CU php can obtain remote content, establish a connection only once, and use it multiple times.
For example:
$ 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 );
The url of the target address is stable and only the parameters passed are different,
Can the code contain only
$ 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 ));
You do not need to create a connection or close a connection each time.
------ Solution --------------------
CURLOPT_CUSTOMREQUEST
------ Solution --------------------
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 = 0 Pragma: no-cacheContent-Length: 257Keep-Alive: timeout = 5, max = 100 Connection: Keep-AliveContent-Type: text/html; charset = utf-8^_^ Hello, welcome to ThinkPHP
GET/HTTP/1.1 Host: 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] $