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 相关文章推荐
实现了一个PHP5的getter/setter基类的代码
Feb 25 PHP
如何在PHP中使用正则表达式进行查找替换
Jun 13 PHP
php删除字符串末尾子字符,删除开始字符,删除两端字符(实现代码)
Jun 27 PHP
php根据身份证号码计算年龄的实例代码
Jan 18 PHP
php面向对象中static静态属性和静态方法的调用
Feb 08 PHP
php修改上传图片尺寸的方法
Apr 14 PHP
php实现在站点里面添加邮件发送的功能
Apr 28 PHP
Yii2.0中的COOKIE和SESSION用法
Aug 12 PHP
php array_slice 取出数组中的一段序列实例
Nov 04 PHP
PHP实现数据库统计时间戳按天分组输出数据的方法
Oct 10 PHP
购物车实现的几种方式优缺点对比
May 02 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
模仿OSO的论坛(一)
2006/10/09 PHP
PHP 线程安全与非线程安全版本的区别深入解析
2013/08/06 PHP
PHP生成条形图的方法
2014/12/10 PHP
Javascript注入技巧
2007/06/22 Javascript
js中单引号与双引号冲突问题解决方法
2013/10/04 Javascript
js转化毫秒为时间格式代码
2014/04/10 Javascript
在Javascript中处理字符串之big()方法的使用
2015/06/08 Javascript
详谈表单格式化插件jquery.serializeJSON
2017/06/23 jQuery
基于js中document.cookie全面解析
2017/09/14 Javascript
详解vue-meta如何让你更优雅的管理头部标签
2018/01/18 Javascript
微信小程序时间戳转日期的详解
2019/04/30 Javascript
深入了解JavaScript 私有化
2019/05/30 Javascript
layer.open回调获取弹出层参数的实现方法
2019/09/10 Javascript
微信小程序跨页面数据传递事件响应实现过程解析
2019/12/19 Javascript
[08:56]DOTA2-DPC中国联赛2月23日Recap集锦
2021/03/11 DOTA
python urllib爬取百度云连接的实例代码
2017/06/19 Python
python3判断url链接是否为404的方法
2018/08/10 Python
解决python3捕获cx_oracle抛出的异常错误问题
2018/10/18 Python
使用django实现一个代码发布系统
2019/07/18 Python
python配置文件写入过程详解
2019/10/19 Python
关于numpy中eye和identity的区别详解
2019/11/29 Python
python中有关时间日期格式转换问题
2019/12/25 Python
python-OpenCV 实现将数组转换成灰度图和彩图
2020/01/09 Python
python装饰器实现对异常代码出现进行自动监控的实现方法
2020/09/15 Python
Python xmltodict模块安装及代码实例
2020/10/05 Python
加拿大领先的时尚和体育零售商:Sporting Life
2019/12/15 全球购物
计算机专业个人求职自荐信
2013/09/21 职场文书
记者岗位职责
2014/01/06 职场文书
2014组织生活会方案
2014/05/19 职场文书
安全生产标语
2014/06/06 职场文书
低碳环保口号
2014/06/12 职场文书
司法助理专业自荐书
2014/06/13 职场文书
毕业论文指导教师评语
2014/12/30 职场文书
PHP对接阿里云虚拟号的实现(号码隐私保护)
2021/04/06 PHP
不负正版帝国之名 《重返帝国》引领SLG手游制作新的标杆
2022/04/07 其他游戏
如何vue使用el-table遍历循环表头和表体数据
2022/04/26 Vue.js