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 管理系统程序中的后门
Aug 05 PHP
PHP正确配置mysql(apache环境)
Aug 28 PHP
php中http_build_query 的一个问题
Mar 25 PHP
如何在PHP中使用正则表达式进行查找替换
Jun 13 PHP
ThinkPHP查询返回简单字段数组的方法
Aug 25 PHP
PHP内存缓存Memcached类实例
Dec 08 PHP
php简单分页类实现方法
Feb 26 PHP
ucenter中词语过滤原理分析
Jul 13 PHP
PHP实现小偷程序实例
Oct 31 PHP
Zend Framework数据库操作技巧总结
Feb 18 PHP
php将从数据库中获得的数据转换成json格式并输出的方法
Aug 21 PHP
PHP 99乘法表的几种实现代码
Oct 13 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
php5.2时间相差8小时
2007/01/15 PHP
php xml留言板 xml存储数据的简单例子
2009/08/24 PHP
PHP APP微信提现接口代码
2018/09/30 PHP
PHP 代码简洁之道(小结)
2019/10/16 PHP
Thinkphp 框架配置操作之动态配置、扩展配置及批量配置实例分析
2020/05/15 PHP
静态图片的十一种滤镜效果--不支持Ie7及非IE浏览器。
2007/03/06 Javascript
javascript+mapbar实现地图定位
2010/04/09 Javascript
javascript 弹出窗口中是否显示地址栏的实现代码
2011/04/14 Javascript
js数组Array sort方法使用深入分析
2013/02/21 Javascript
jquery队列函数用法实例
2014/12/16 Javascript
在JavaScript中操作时间之getYear()方法的使用教程
2015/06/11 Javascript
jQuery简单获取键盘事件的方法
2016/01/22 Javascript
vue.js入门教程之计算属性
2016/09/01 Javascript
基于jQuery的select下拉框选择触发事件实例分析
2016/11/18 Javascript
JS判断一个数是否是水仙花数
2017/06/11 Javascript
浅谈Vue2.0中v-for迭代语法的变化(key、index)
2018/03/06 Javascript
Node.js中的cluster模块深入解读
2018/06/11 Javascript
关于TypeScript模块导入的那些事
2018/06/12 Javascript
JS无限级导航菜单实现方法
2019/01/05 Javascript
微信小程序视频弹幕发送功能的实现
2020/12/28 Javascript
Python实现的圆形绘制(画圆)示例
2018/01/31 Python
Python实现读写INI配置文件的方法示例
2018/06/09 Python
Python小游戏之300行代码实现俄罗斯方块
2019/01/04 Python
Python列表(list)所有元素的同一操作解析
2019/08/01 Python
Python with语句和过程抽取思想
2019/12/23 Python
python中有函数重载吗
2020/05/28 Python
python中count函数知识点浅析
2020/12/17 Python
详解HTML5中的标签
2015/06/19 HTML / CSS
入党积极分子思想汇报
2014/01/02 职场文书
爱护公共设施的标语
2014/06/24 职场文书
单位工作证明范文
2014/09/14 职场文书
餐厅服务员岗位职责
2015/02/09 职场文书
2015年团支部年度工作总结
2015/05/27 职场文书
家装电话营销开场白
2015/05/29 职场文书
Redisson实现Redis分布式锁的几种方式
2021/08/07 Redis
MongoDB误操作后使用oplog恢复数据
2022/04/11 MongoDB