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算开始时间到过期时间的相隔的天数
Jan 12 PHP
PHP中获取内网用户MAC地址(WINDOWS/linux)的实现代码
Aug 11 PHP
php array的学习笔记
May 16 PHP
php的webservice的wsdl的XML无法显示问题的解决方法
Mar 11 PHP
PHP7.0版本备注
Jul 23 PHP
php mysqli查询语句返回值类型实例分析
Jun 29 PHP
PHP提取字符串中的手机号正则表达式怎么写
Jul 17 PHP
php7安装yar扩展的方法详解
Aug 03 PHP
PHP排序算法之快速排序(Quick Sort)及其优化算法详解
Apr 21 PHP
PHP+redis实现的悲观锁机制示例
Jun 12 PHP
PHP中检查isset()和!empty()函数的必要性
Feb 13 PHP
PHP levenshtein()函数用法讲解
Mar 08 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
Apache中php.ini的设置方法
2013/02/28 PHP
php数组去重实例及分析
2013/11/26 PHP
深入剖析浏览器退出之后php还会继续执行么
2016/05/17 PHP
PHP设计模式之原型模式定义与用法详解
2018/04/03 PHP
jQuery 开天辟地入门篇一
2009/12/09 Javascript
jquery的ajaxSubmit()异步上传图片并保存表单数据演示代码
2013/06/04 Javascript
用jQuery实现一些导航条切换,显示隐藏的实例代码
2013/06/08 Javascript
获取下拉列表框的值是数组,split,$.inArray示例
2013/11/13 Javascript
利用javascript实现禁用网页上所有文本框,下拉菜单,多行文本域
2013/12/14 Javascript
jQuery实现的fixedMenu下拉菜单效果代码
2015/08/24 Javascript
javascript下拉列表菜单的实现方法
2015/11/18 Javascript
javascript类型系统 Window对象学习笔记
2016/01/07 Javascript
AngularJs动态加载模块和依赖注入详解
2016/01/11 Javascript
JavaScript笔记之数据属性和存储器属性
2016/03/31 Javascript
JavaScript语言精粹经典实例(整理篇)
2016/06/07 Javascript
JS中页面与页面之间超链接跳转中文乱码问题的解决办法
2016/12/15 Javascript
canvas实现图片根据滑块放大缩小效果
2017/02/24 Javascript
vue 导航守卫和axios拦截器有哪些区别
2020/12/19 Vue.js
Python中的对象,方法,类,实例,函数用法分析
2015/01/15 Python
Python中列表list以及list与数组array的相互转换实现方法
2017/09/22 Python
Python爬虫番外篇之Cookie和Session详解
2017/12/27 Python
Python实现八皇后问题示例代码
2018/12/09 Python
python 实现查找文件并输出满足某一条件的数据项方法
2019/06/12 Python
PyTorch中topk函数的用法详解
2020/01/02 Python
CSS3制作圆形滚动进度条动画的示例
2020/11/05 HTML / CSS
英国No.1文具和办公用品在线:Euroffice
2016/09/21 全球购物
自荐信封面
2013/12/04 职场文书
银行演讲稿范文
2014/01/03 职场文书
说明书怎么写
2014/05/06 职场文书
物理课外活动总结
2014/08/27 职场文书
运动会广播稿100字
2014/09/14 职场文书
高中班主任评语
2014/12/30 职场文书
新生开学寄语大全
2015/05/28 职场文书
python实现腾讯滑块验证码识别
2021/04/27 Python
Python OpenCV 图像平移的实现示例
2021/06/04 Python
7个关于Python的经典基础案例
2021/11/07 Python