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.0对象模型探索之抽象方法和抽象类
Sep 05 PHP
非常不错的MySQL优化的8条经验
Mar 24 PHP
php出现Cannot modify header information问题的解决方法大全
Apr 09 PHP
PHP 开源AJAX框架14种
Aug 24 PHP
php更新mysql后获取影响的行数发生异常解决方法
Mar 28 PHP
PHP使用GETDATE获取当前日期时间作为一个关联数组的方法
Mar 19 PHP
PHP6新特性分析
Mar 03 PHP
Yii2中datetime类的使用
Dec 17 PHP
详解php与ethereum客户端交互
Apr 28 PHP
php 调用百度sms来发送短信的实现示例
Nov 02 PHP
PHP实现统计代码行数小工具
Sep 19 PHP
Yii 框架使用Forms操作详解
May 18 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+mysql写的留言本
2006/10/09 PHP
Yii2-GridView 中让关联字段带搜索和排序功能示例
2017/01/21 PHP
Win10 下安装配置IIS + MySQL + nginx + php7.1.7
2017/08/04 PHP
PHP基于迭代实现文件夹复制、删除、查看大小等操作的方法
2017/08/11 PHP
javascript 日期时间函数(经典+完善+实用)
2009/05/27 Javascript
javascript实现的一个带下拉框功能的文本框
2014/05/08 Javascript
javascript制作sql转换为stringBuffer的小工具
2015/04/03 Javascript
Vue常用指令V-model用法
2017/03/08 Javascript
微信小程序 弹框和模态框实现代码
2017/03/10 Javascript
JS正则验证多个邮箱完整实例【邮箱用分号隔开】
2017/04/19 Javascript
微信小程序实现多个按钮toggle功能的实例
2017/06/13 Javascript
react中fetch之cors跨域请求的实现方法
2018/03/14 Javascript
从零开始搭建vue移动端项目到上线的步骤
2018/10/15 Javascript
通过循环优化 JavaScript 程序
2019/06/24 Javascript
jQuery zTree插件快速实现目录树
2019/08/16 jQuery
JavaScript布尔运算符原理使用解析
2020/05/06 Javascript
python清理子进程机制剖析
2017/11/23 Python
python计算两个数的百分比方法
2018/06/29 Python
celery4+django2定时任务的实现代码
2018/12/23 Python
自学python的建议和周期预算
2019/01/30 Python
Python任意字符串转16, 32, 64进制的方法
2019/06/12 Python
python输出电脑上所有的串口名的方法
2019/07/02 Python
Python scipy的二维图像卷积运算与图像模糊处理操作示例
2019/09/06 Python
wxPython实现画图板
2020/08/27 Python
python thrift 实现 单端口多服务的过程
2020/06/08 Python
Python中的With语句的使用及原理
2020/07/29 Python
10个python爬虫入门实例(小结)
2020/11/01 Python
CSS3模块的目前的状况分析
2010/02/24 HTML / CSS
让IE下支持Html5的placeholder属性的插件
2014/09/02 HTML / CSS
Bluebella美国官网:英国性感内衣品牌
2018/10/04 全球购物
常务副总经理岗位职责
2014/04/12 职场文书
525心理活动总结
2014/07/04 职场文书
环境监测与治理技术专业求职信
2014/07/06 职场文书
观后感开头
2015/06/19 职场文书
如何把新闻人物写得立体、鲜活?
2019/08/14 职场文书
简单了解 MySQL 中相关的锁
2021/05/25 MySQL