PHPcURL initialization and execution method entry-level code, curl initialization. PHPcURL initialization and execution method entry-level code. curl initialization is the basis for collection. it is best to familiarize yourself with $ chcurl_init (); # set the url and return the result, whether to return header curl _ PHP cURL initialization and execution method entry-level code, curl initialization
This is the basis for data collection.
$ Ch = curl_init (); # set the url and return the result. whether to return the header curl_setopt ($ ch, CURLOPT_URL ,' http://www.baidu.com/ '); Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ this-> ch, CURLOPT_HEADER, 1); # curl_setopt ($ this-> ch, CURLOPT_COOKIEJAR, $ cookie_file); curl_setopt ($ this-> ch, CURLOPT_COOKIEFILE, $ cookie_file); # extra header curl_setopt ($ this-> ch, CURLOPT_HTTPHEADER, array ('User-Agent: mozilla/5.0 '); # set postcurl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ poststring ); # connection and execution expiration time curl_setopt ($ this-> ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt ($ this-> ch, CURLOPT_TIMEOUT, 30 ); # follow 301 302curl_setopt ($ this-> ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ this-> ch, CURLOPT_MAXREDIRS, 10); # refercurl_setopt ($ this-> ch, CURLOPT_REFERER, $ refer); # set curl_setopt for http version and Port reuse ($ this-> ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt ($ this-> ch, forward, 1 ); # support httpscurl_setopt ($ this-> ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt ($ this-> ch, CURLOPT_SSL_VERIFYHOST, 0); # if millisecond timeout is required, add: curl_setopt ($ this-> ch, CURLOPT_NOSIGNAL, 1); # run $ response = curl_exec ($ ch); if (curl_errno ($ ch) {curl_error ($ ch ); exit ();} curl_close ($ ch );
Http://www.bkjia.com/PHPjc/1008002.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1008002.htmlTechArticlePHP cURL initialization and execution method entry-level code, curl initialization this is the basis of collection, it is best to get familiar with $ ch = curl_init (); # set the url and return the results, whether to return the header curl _...