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 相关文章推荐
无限级别菜单的实现
Oct 09 PHP
php简单封装了一些常用JS操作
Feb 25 PHP
phpmyadmin3 安装配置图解教程
Mar 29 PHP
php源代码安装常见错误与解决办法分享
May 28 PHP
PHP删除HTMl标签的实现代码
Jun 30 PHP
PHP中HTML标签过滤技巧
Jan 07 PHP
PHPThumb图片处理实例
May 03 PHP
优化WordPress中文章与评论的时间显示
Jan 12 PHP
ThinkPHP框架搭建及常见问题(XAMPP安装失败、Apache/MySQL启动失败)
Apr 15 PHP
PHP判断JSON对象是否存在的方法(推荐)
Jul 06 PHP
基于PHP制作验证码
Oct 12 PHP
XAMPP升级PHP版本实现步骤解析
Sep 04 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
Adodb的十个实例(清晰版)
2006/12/31 PHP
php缩放gif和png图透明背景变成黑色的解决方法
2014/10/14 PHP
php实现发送微信模板消息的方法
2015/03/07 PHP
Yii使用smsto短信接口的函数demo示例
2016/07/13 PHP
laravel实现上传图片并在页面显示的例子
2019/10/14 PHP
jQuery实现原理的模拟代码 -6 代码下载
2010/08/16 Javascript
图片延迟加载的实现代码(模仿懒惰)
2013/03/29 Javascript
使用js实现雪花飘落效果
2013/08/26 Javascript
密码框显示提示文字jquery示例
2013/08/29 Javascript
javascript实现倒计时N秒后网页自动跳转代码
2014/12/11 Javascript
Jquery使用val方法读写value值
2015/05/18 Javascript
js动态生成Html元素实现Post操作(createElement)
2015/09/14 Javascript
全面解析Bootstrap中Carousel轮播的使用方法
2016/06/13 Javascript
AngularJS基于factory创建自定义服务的方法详解
2017/05/25 Javascript
Angularjs为ng-click事件传递参数
2017/06/15 Javascript
NodeJS实现一个聊天室功能
2019/11/25 NodeJs
Vue-resource安装过程及使用方法解析
2020/07/21 Javascript
vue axios封装httpjs,接口公用配置拦截操作
2020/08/11 Javascript
[02:41]2015国际邀请赛中国区预选赛观战指南
2015/05/20 DOTA
[01:15]《辉夜杯》北京网鱼队巡礼
2015/10/26 DOTA
python字典的遍历3种方法详解
2019/08/10 Python
Django之使用内置函数和celery发邮件的方法示例
2019/09/16 Python
Python实现串口通信(pyserial)过程解析
2019/09/25 Python
TensorFlow实现打印每一层的输出
2020/01/21 Python
python代码实现TSNE降维数据可视化教程
2020/02/28 Python
Python 连接 MySQL 的几种方法
2020/09/09 Python
python实现测试工具(二)——简单的ui测试工具
2020/10/19 Python
Css3新特性应用之视觉效果实例
2016/12/12 HTML / CSS
教师党员思想汇报
2014/01/06 职场文书
社区健康教育实施方案
2014/03/18 职场文书
大学理论知识学习自我鉴定
2014/04/28 职场文书
做人民满意的公务员活动方案
2014/08/25 职场文书
2015年学校医务室工作总结
2015/07/20 职场文书
学生病假条怎么写
2015/08/17 职场文书
《亲亲我的妈妈》观后感(3篇)
2019/09/26 职场文书
试用1103暨1103、1101同门大比武 [ DAIWEI ]
2022/04/05 无线电