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中的CMS的涵义
Mar 11 PHP
PHP中strtotime函数使用方法分享
Jan 10 PHP
php使用for语句输出三角形的方法
Jun 09 PHP
PHPStrom中实用的功能和快捷键大全
Sep 23 PHP
适用于初学者的简易PHP文件上传类
Oct 29 PHP
PHP图片加水印实现方法
May 06 PHP
smarty循环嵌套用法示例分析
Jul 19 PHP
php微信公众账号开发之前五个坑(一)
Sep 18 PHP
PHP实现的大文件切割与合并功能示例
Apr 10 PHP
详解php与ethereum客户端交互
Apr 28 PHP
PHP7内核CGI与FastCGI详解
Apr 14 PHP
open_basedir restriction in effect. 原因与解决方法
Mar 14 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中使用PDF文档功能
2006/10/09 PHP
PHP 选项及相关信息函数库
2006/12/04 PHP
Ajax提交表单时验证码自动验证 php后端验证码检测
2016/07/20 PHP
php7安装mongoDB扩展的方法分析
2017/08/02 PHP
ThinkPHP5&5.1框架关联模型分页操作示例
2019/08/03 PHP
动态加载js文件 document.createElement
2006/10/14 Javascript
基于jquery实现控制经纬度显示地图与卫星
2013/05/20 Javascript
使用js实现雪花飘落效果
2013/08/26 Javascript
ExtJs中gridpanel分组后组名排序实例代码
2013/12/02 Javascript
jQuery延迟加载图片插件Lazy Load使用指南
2015/03/25 Javascript
javascript关于运动的各种问题经典总结
2015/04/27 Javascript
基于JavaScript实现仿京东图片轮播效果
2015/11/06 Javascript
BootStrap中Tab页签切换实例代码
2016/05/30 Javascript
Javascript发送AJAX请求实例代码
2016/08/21 Javascript
jQuery的三种bind/One/Live/On事件绑定使用方法
2017/02/23 Javascript
Angularjs自定义指令Directive详解
2017/05/27 Javascript
JavaScript数组_动力节点Java学院整理
2017/06/26 Javascript
angular2实现统一的http请求头方法
2018/08/13 Javascript
JavaScript实现简单随机点名器
2019/11/21 Javascript
js实现带积分弹球小游戏
2020/07/21 Javascript
[02:04]2014DOTA2国际邀请赛 BBC小组赛第三天总结
2014/07/12 DOTA
Python中使用Beautiful Soup库的超详细教程
2015/04/30 Python
python获取文件扩展名的方法
2015/07/06 Python
win7上python2.7连接mysql数据库的方法
2017/01/14 Python
Python Web程序部署到Ubuntu服务器上的方法
2018/02/22 Python
使用Python做定时任务及时了解互联网动态
2019/05/15 Python
numpy中的meshgrid函数的使用
2019/07/31 Python
python打印直角三角形与等腰三角形实例代码
2019/10/20 Python
python_mask_array的用法
2020/02/18 Python
Python flask框架实现查询数据库并显示数据
2020/06/04 Python
基于css3实现漂亮便签样式
2013/03/18 HTML / CSS
三八活动策划方案
2014/08/17 职场文书
村安全生产责任书
2014/08/25 职场文书
垂直极限观后感
2015/06/08 职场文书
退休欢送会主持词
2015/07/01 职场文书
推荐六本经典文学奖书籍:此生必读
2019/08/22 职场文书