phprecv
A. php 用CURL 抓取錯誤提示:Recv failure: Connection was aborted 怎麼解決 求助各位大神
一、原因分析
web站點目前主要分為http和https兩種協議,其中https類型的網站都是通過ssl協議+http協議的,是目前最安全的網站協議,訪問此類網站的時候,會走ssl協議,驗證訪問者的證書,檢測是否安全。
通過curl訪問此類網站也是如此流程,但是curl中需要添加相應的參數,繞過ssl證書的驗證,才可以正常訪問,如出現此錯誤的一般原因是沒有加此參數。
CURLOPT_SSL_VERIFYHOST的值
設為0表示不檢查證書
設為1表示檢查證書中是否有CN(common name)欄位
設為2表示在1的基礎上校驗當前的域名是否與CN匹配。
二、解決方案
如果出現:
PHP Notice: curl_setopt():
CURLOPT_SSL_VERIFYHOST with value 1 is deprecated and will be removed as of libcurl 7.28.1. It is recommended to use value 2 instead in
一般原因是你設置了 curl_setopt ( $curl_handle, CURLOPT_SSL_VERIFYHOST, true );
改成curl_setopt ( $curl_handle, CURLOPT_SSL_VERIFYHOST, 2 );就行了。
(1)phprecv擴展閱讀
PHP其他原因錯誤:
1、錯誤現象
在用curl進行模擬調用時,curl接收內容會出現"Empty reply from server" 和 "Recv failure: Connection was reset"的錯誤。
2、解決方案
經過對apache的error_log進行跟蹤,出現錯誤"Connection reset by peer: core_output_filter: writing data to the network"
修改httpd.conf,在虛擬主機上添加如下內容:
EnableSendfile off
EnableMMAP off
修改後"Empty reply from server"錯誤消失。