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中计算中文字符串长度、截取中文字符串的函数代码
Aug 09 PHP
php简单浏览目录内容的实现代码
Jun 07 PHP
图解找出PHP配置文件php.ini的路径的方法
Aug 20 PHP
php生成xml时添加CDATA标签的方法
Oct 17 PHP
php异步多线程swoole用法实例
Nov 14 PHP
php可生成缩略图的文件上传类实例
Dec 17 PHP
php post大量数据时发现数据丢失问题解决方法
Jun 20 PHP
PHP+MYSQL中文乱码问题
Jul 01 PHP
thinkphp autoload 命名空间自定义 namespace
Jul 17 PHP
Laravel实现自定义错误输出内容的方法
Oct 10 PHP
浅析PHP中的闭包和匿名函数
Dec 25 PHP
php+js实现的拖动滑块验证码验证表单操作示例【附源码下载】
May 27 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遍历目录函数opendir()、readdir()、closedir()、rewinddir()总结
2014/11/18 PHP
PHPExcel内存泄漏问题解决方法
2015/01/23 PHP
php对数组内元素进行随机调换的方法
2015/05/12 PHP
php中青蛙跳台阶的问题解决方法
2018/10/14 PHP
如何运行/调试你的PHP代码
2020/10/23 PHP
JS解决url传值出现中文乱码的另类办法
2013/04/08 Javascript
JQuery调webservice实现邮箱验证(检测是否可用)
2013/05/21 Javascript
Javascript学习笔记之函数篇(六) : 作用域与命名空间
2014/11/23 Javascript
JS实现动态移动层及拖动浮层关闭的方法
2015/04/30 Javascript
JavaScript中var关键字的使用详解
2015/08/14 Javascript
JS实现鼠标框选效果完整实例
2016/06/20 Javascript
jQuery插件学习教程之SlidesJs轮播+Validation验证
2016/07/12 Javascript
Angularjs中$http以post请求通过消息体传递参数的实现方法
2016/08/05 Javascript
jQuery的deferred对象使用详解
2016/09/25 Javascript
理解AngularJs篇:30分钟快速掌握AngularJs
2016/12/23 Javascript
基于Vue实现timepicker
2017/04/25 Javascript
JS实现移动端判断上拉和下滑功能
2017/08/07 Javascript
js实现随机点名小功能
2017/08/17 Javascript
浅谈Webpack打包优化技巧
2018/06/12 Javascript
jQuery实现的自定义轮播图功能详解
2018/12/28 jQuery
JS实现的贪吃蛇游戏完整实例
2019/01/18 Javascript
基于vue、react实现倒计时效果
2019/08/26 Javascript
[51:52]Liquid vs Secret 2019国际邀请赛淘汰赛 败者组 BO3 第二场 8.24
2019/09/10 DOTA
Python爬虫框架Scrapy常用命令总结
2018/07/26 Python
django使用LDAP验证的方法示例
2018/12/10 Python
python提取包含关键字的整行数据方法
2018/12/11 Python
快速排序的四种python实现(推荐)
2019/04/03 Python
C++的几个面试题附答案
2016/08/03 面试题
最新自我评价范文
2013/11/16 职场文书
高中军训感言500字
2014/02/24 职场文书
2014爱耳日宣传教育活动总结
2014/03/09 职场文书
《得道多助,失道寡助》教学反思
2014/04/19 职场文书
租车协议书
2015/01/27 职场文书
2015年超市工作总结范文
2015/05/26 职场文书
辩论赛开场白大全(主持人+辩手)
2015/05/29 职场文书
2016优秀大学生个人事迹材料范文
2016/03/01 职场文书