這篇文章將為大家詳細講解有關PHP的cURL初始化和執(zhí)行方法介紹,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。
這個是采集基礎,好熟悉一下
$ch = curl_init(); # 設定url和把結果返回,是否返回頭部 curl_setopt($ch, CURLOPT_URL, 'http://www.baidu.com/'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($this->ch, CURLOPT_HEADER, 1); # cookie文件設定 curl_setopt($this->ch, CURLOPT_COOKIEJAR, $cookie_file); curl_setopt($this->ch, CURLOPT_COOKIEFILE, $cookie_file); # 額外頭部 curl_setopt($this->ch, CURLOPT_HTTPHEADER, array('User-Agent: Mozilla/5.0')); # 設定post curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $poststring); # 連接、執(zhí)行過期時間 curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($this->ch, CURLOPT_TIMEOUT, 30); # 是否跟隨301 302 curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($this->ch, CURLOPT_MAXREDIRS, 10); # refer curl_setopt($this->ch, CURLOPT_REFERER, $refer); # http版本和端口重用設置 curl_setopt($this->ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($this->ch, CURLOPT_FORBID_REUSE, 1); # 支持https curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 0); # 如果需要進行毫秒超時,需要增加: curl_setopt($this->ch, CURLOPT_NOSIGNAL, 1); # 執(zhí)行 $response = curl_exec($ch); if(curl_errno($ch)){ curl_error($ch); exit(); } curl_close($ch);
關于PHP的cURL初始化和執(zhí)行方法介紹就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
網(wǎng)站名稱:PHP的cURL初始化和執(zhí)行方法介紹-創(chuàng)新互聯(lián)
當前URL:http://chinadenli.net/article0/decgio.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、標簽優(yōu)化、微信小程序、外貿網(wǎng)站建設、網(wǎng)站策劃、網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)