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 相关文章推荐
如何将数据从文本导入到mysql
Oct 09 PHP
Php做的端口嗅探器--可以指定网站和端口
Oct 09 PHP
php设计模式 Adapter(适配器模式)
Jun 26 PHP
php提示Call-time pass-by-reference has been deprecated in的解决方法[已测]
May 06 PHP
php中json_encode处理gbk与gb2312中文乱码问题的解决方法
Jul 10 PHP
PHP中实现获取IP和地理位置类分享
Feb 10 PHP
PHP简单创建压缩图的方法
Aug 24 PHP
php 使用html5实现多文件上传实例
Oct 24 PHP
yii2使用GridView实现数据全选及批量删除按钮示例
Mar 01 PHP
PHP children()函数讲解
Feb 03 PHP
laravel 5.5 关闭token的3种实现方式
Oct 24 PHP
php操作redis数据库常见方法实例总结
Feb 20 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
解析php中memcache的应用
2013/06/18 PHP
php中convert_uuencode()与convert_uuencode函数用法实例
2014/11/22 PHP
PHP7 windows支持
2021/03/09 PHP
兼容FF和IE的动态table示例自写
2013/10/21 Javascript
解析JSON对象与字符串之间的相互转换
2013/12/18 Javascript
jquery插件开发之实现google+圈子选择功能
2014/03/10 Javascript
javascript实现漂亮的拖动层,窗口拖拽特效
2015/04/24 Javascript
JavaScript组件开发完整示例
2015/12/15 Javascript
封装好的javascript前端分页插件pagination
2016/01/04 Javascript
JavaScript实现的SHA-1加密算法完整实例
2016/02/02 Javascript
Vue插件写、用详解(附demo)
2017/03/20 Javascript
详解angularJs指令的3种绑定策略
2017/04/13 Javascript
JavaScript切换搜索引擎的导航网页搜索框实例代码
2017/06/11 Javascript
详解webpack 入门总结和实践(按需异步加载,css单独打包,生成多个入口文件)
2017/06/20 Javascript
js中let和var定义变量的区别
2018/02/08 Javascript
Vue组件库发布到npm详解
2018/02/17 Javascript
vue中的ref和$refs的使用
2018/11/22 Javascript
微信小程序实现判断是分享到群还是个人功能示例
2019/05/03 Javascript
vue实现带过渡效果的下拉菜单功能
2020/02/19 Javascript
JavaScript如何实现图片处理与合成
2020/05/29 Javascript
Vue-resource安装过程及使用方法解析
2020/07/21 Javascript
在Python中操作列表之List.append()方法的使用
2015/05/20 Python
简单解决Python文件中文编码问题
2015/11/22 Python
十分钟利用Python制作属于你自己的个性logo
2018/05/07 Python
美国顶级水上运动专业店:Marine Products
2018/04/15 全球购物
一些Unix笔试题和面试题
2012/09/25 面试题
公司董事长职责
2013/12/12 职场文书
销售演讲稿范文
2014/01/08 职场文书
物业管理计划书
2014/01/10 职场文书
《商鞅南门立木》教学反思
2014/02/16 职场文书
单位消防安全责任书
2014/07/23 职场文书
医院2014国庆节活动策划方案
2014/09/21 职场文书
2015年社区民政工作总结
2015/04/21 职场文书
捐款通知怎么写
2015/04/24 职场文书
征求意见函
2015/06/05 职场文书
Python并发编程实例教程之线程的玩法
2021/06/20 Python