PHP CURL 内存泄露问题解决方法


Posted in PHP onFebruary 12, 2015

phpcurl使用privoxy代理访问https://www.google.com/search?q=xxx

curl配置平淡无奇,长时间运行发现一个严重问题,内存泄露!不论用单线程和多线程都无法避免!是curl访问https站点的时候有bug!
内存泄露可以通过linux的top命令发现,使用php函数memory_get_usage()不会发现。

经过反复调试找到解决办法,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 相关文章推荐
php UTF8 文件的签名问题
Oct 30 PHP
php不用内置函数对数组排序的两个算法代码
Feb 08 PHP
PHP写UltraEdit插件脚本实现方法
Dec 26 PHP
Zend Studio 实用快捷键一览表(精心整理)
Aug 10 PHP
php mysql_real_escape_string函数用法与实例教程
Sep 30 PHP
PHP利用func_get_args和func_num_args函数实现函数重载实例
Nov 12 PHP
PHP中if和or运行效率对比
Dec 12 PHP
优化WordPress的Google字体以加速国内服务器上的运行
Nov 24 PHP
基于PHP代码实现中奖概率算法可用于刮刮卡、大转盘等抽奖算法
Dec 20 PHP
php gd等比例缩放压缩图片函数
Jun 12 PHP
PHP获取当前执行php文件名的代码
Mar 02 PHP
php设计模式之策略模式应用案例详解
Jun 17 PHP
PHP中捕获超时事件的方法实例
Feb 12 #PHP
php单例模式示例分享
Feb 12 #PHP
PHP 正则表达式小结
Feb 12 #PHP
一个非常完美的读写ini格式的PHP配置类分享
Feb 12 #PHP
PHP动态输出JavaScript代码实例
Feb 12 #PHP
PHP使用JSON和将json还原成数组
Feb 12 #PHP
服务器上配置PHP运行环境教程
Feb 12 #PHP
You might like
frename PHP 灵活文件命名函数 frename
2009/09/09 PHP
Laravel中使用Queue的最基本操作教程
2017/12/27 PHP
Add Formatted Text to a Word Document
2007/06/15 Javascript
jquery $.ajax入门应用二
2008/11/19 Javascript
JavaScript 读取元素的CSS信息的代码
2010/02/07 Javascript
基于Jquery的仿照flash放大图片效果代码
2011/03/16 Javascript
js iframe跨域访问(同主域/非同主域)分别深入介绍
2013/01/24 Javascript
jquery的ajax请求全面了解
2013/03/20 Javascript
关于IE中getElementsByClassName不能用的问题解决方法
2013/08/26 Javascript
js单例模式详解实例
2013/11/21 Javascript
JavaScript将页面表格导出为Excel的具体实现
2013/12/27 Javascript
JavaScript中的索引数组、关联数组和静态数组、动态数组讲解
2014/11/08 Javascript
浅析node.js中close事件
2014/11/26 Javascript
浅谈Webpack下多环境配置的思路
2018/06/27 Javascript
vue插件实现v-model功能
2018/09/10 Javascript
vue实现pdf导出解决生成canvas模糊等问题(推荐)
2018/10/18 Javascript
JavaScript ES6常用基础知识总结
2019/02/09 Javascript
JS实现简单的表格增删
2020/01/16 Javascript
JS实现打砖块游戏
2020/02/14 Javascript
Javascript实现简易天数计算器
2020/05/18 Javascript
python实现2014火车票查询代码分享
2014/01/10 Python
Python3中内置类型bytes和str用法及byte和string之间各种编码转换 问题
2018/09/27 Python
python实现趣味图片字符化
2019/04/30 Python
浅谈SciPy中的optimize.minimize实现受限优化问题
2020/02/29 Python
Keras之自定义损失(loss)函数用法说明
2020/06/10 Python
Python基于Socket实现简易多人聊天室的示例代码
2020/11/29 Python
css和css3弹性盒模型实现元素宽度(高度)自适应
2019/05/15 HTML / CSS
瑞士网球商店:Tennis-Point
2020/03/12 全球购物
职高毕业生自我鉴定
2013/10/21 职场文书
实习生评语
2014/04/26 职场文书
结对共建工作方案
2014/06/02 职场文书
工厂仓管员岗位职责范本
2014/07/17 职场文书
《中国梦我的梦》中学生演讲稿
2014/08/20 职场文书
标准大学生职业生涯规划书写作指南
2014/09/18 职场文书
合同范本之电脑出租
2019/08/13 职场文书
解决SpringBoot跨域的三种方式
2021/06/26 Java/Android