PHP CURL 內(nèi)存泄露問題解決方法
phpcurl使用privoxy代理訪問https://www.google.com/search?q=xxx
curl配置平淡無奇,長時間運行發(fā)現(xiàn)一個嚴(yán)重問題,內(nèi)存泄露!不論用單線程和多線程都無法避免!是curl訪問https站點的時候有bug!
內(nèi)存泄露可以通過linux的top命令發(fā)現(xiàn),使用php函數(shù)memory_get_usage()不會發(fā)現(xiàn)。
經(jīng)過反復(fù)調(diào)試找到解決辦法,curl配置添加如下幾項解決問題:
[CURLOPT_HTTPPROXYTUNNEL] = true;
[CURLOPT_SSL_VERIFYPEER] = false;
[CURLOPT_SSL_VERIFYHOST] = false;
CURLOPT_HTTPPROXYTUNNEL具體說明stackoverflow上有,直接貼原文:
Without CURLOPT_HTTPPROXYTUNNEL
Without CURLOPT_HTTPPROXYTUNNEL : You just use the proxy address/port as a destination of your HTTP request. The proxy will read the HTTP headers of your query, forward your request to the destination (with your HTTP headers) and then write the response to you.
Example steps :
1)HTTP GET /index.html sent to 1.1.1.1 (proxy)
2)1.1.1.1 receive request and parse header for getting the final destination of your HTTP request.
3)1.1.1.1 forward your query and headers to www.site.com (destination in request headers).
4)1.1.1.1 write back to you the response receive from www.site.com
With CURLOPT_HTTPPROXYTUNNEL
With CURLOPT_HTTPPROXYTUNNEL : You ask the proxy to open a direct binary connection (like HTTPS, called a TCP Tunnel) directly to your destination by doing a CONNECT HTTP request. When the tunnel is ok, the proxy write you back a HTTP/1.1 200 Connection established. When it received your browser start to query the destination directly : The proxy does not parse HTTP headers and theoretically does not read tunnel datas, it just forward it, thats why it is called a tunnel !
Example steps :
1)HTTP CONNECT sent to 1.1.1.1
2)1.1.1.1 receive HTTP CONNECT and get the ip/port of your final destination (header field of HTTP CONNECT).
3)1.1.1.1 open a TCP Socket by doing a TCP handshake to your destination 2.22.63.73:80 (ip/port of www.site.com).
4)1.1.1.1 Make a tunnel by piping your TCP Socket to the TCP Socket opened to 2.22.63.73:80and then write you back HTTP/1.1 200 Connection established witch means that your client can now make your query throw the TCP Tunnel (TCP datas received will be transmited directly to server and vice versa).
http://stackoverflow.com/questions/12288956/what-is-the-curl-option-curlopt-httpproxytunnel-means
- PHP使用CURL_MULTI實現(xiàn)多線程采集的例子
- 解析php中curl_multi的應(yīng)用
- php中的curl_multi系列函數(shù)使用例子
- PHP使用curl_multi實現(xiàn)并發(fā)請求的方法示例
- php curl post 時出現(xiàn)的問題解決
- 關(guān)于PHP的curl開啟問題探討
- php使用curl詳細解析及問題匯總
- php5.2的curl-bug 服務(wù)器被php進程卡死問題排查
- php中curl和soap方式請求服務(wù)超時問題的解決
- PHP使用curl_multi_select解決curl_multi網(wǎng)頁假死問題的方法
相關(guān)文章
php函數(shù)mkdir實現(xiàn)遞歸創(chuàng)建層級目錄
當(dāng)我們想在自己的站點中添加多級目錄時,可以運用php函數(shù)mkdir()來實現(xiàn)這個功能。具有一定的參考價值,感興趣的小伙伴們可以參考一下。2016-10-10
Laravel統(tǒng)一封裝接口返回狀態(tài)實例講解
這篇文章主要介紹了Laravel統(tǒng)一封裝接口返回狀態(tài)實例講解,封裝接口返回狀態(tài)有利于前后端分離項目的合作開發(fā),有正好需要的同學(xué)可以研究下2021-03-03
thinkPHP3.0框架實現(xiàn)模板保存到數(shù)據(jù)庫的方法
這篇文章主要介紹了thinkPHP3.0框架實現(xiàn)模板保存到數(shù)據(jù)庫的方法,結(jié)合實例形式分析了使用thinkPHP3.0框架開發(fā)CMS系統(tǒng)過程中將模板保存到數(shù)據(jù)庫的具體實現(xiàn)步驟與相關(guān)操作技巧,需要的朋友可以參考下2017-08-08
destoon實現(xiàn)調(diào)用熱門關(guān)鍵字的方法
這篇文章主要介紹了destoon實現(xiàn)調(diào)用熱門關(guān)鍵字的方法,對于進行模板開發(fā)來說非常有用,需要的朋友可以參考下2014-07-07
thinkphp5.1 框架導(dǎo)入/導(dǎo)出excel文件操作示例
這篇文章主要介紹了thinkphp5.1 框架導(dǎo)入/導(dǎo)出excel文件操作,結(jié)合實例形式分析了thinkphp5.1 框架導(dǎo)入/導(dǎo)出excel文件具體操作實現(xiàn)技巧與相關(guān)注意事項,需要的朋友可以參考下2020-05-05
Laravel 5.5基于內(nèi)置的Auth模塊實現(xiàn)前后臺登陸詳解
最近在使用laravel5.5,利用其實現(xiàn)了一個功能,下面分享給大家,這篇文章主要給大家介紹了關(guān)于Laravel 5.5基于內(nèi)置的Auth模塊如何實現(xiàn)前后臺登陸的相關(guān)資料,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-12-12

