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.ini中文版(1)
Oct 09 PHP
php 多关键字 高亮显示实现代码
Apr 23 PHP
PHP中的Memcache详解
Apr 05 PHP
php设计模式之单例模式实例分析
Feb 25 PHP
全面解读PHP的人气开发框架Laravel
Oct 15 PHP
教大家制作简单的php日历
Nov 17 PHP
yii2超好用的日期组件和时间组件
May 05 PHP
Laravel最佳分割路由文件(routes.php)的方式
Aug 04 PHP
php、java、android、ios通用的3des方法(推荐)
Sep 09 PHP
laravel多条件查询方法(and,or嵌套查询)
Oct 09 PHP
Laravel 错误提示本地化的实现
Oct 22 PHP
php的lavarel框架中join和orWhere的用法
Dec 28 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
收听短波不可能有声音清晰的品质吗
2021/03/01 无线电
PHP下用rmdir实现删除目录的三种方法小结
2008/04/20 PHP
11个PHP 分页脚本推荐
2011/08/15 PHP
CI框架在CLI下执行占用内存过大问题的解决方法
2014/06/17 PHP
PHP设计模式之简单投诉页面实例
2016/02/24 PHP
jquery Firefox3.5中操作select的问题
2009/07/10 Javascript
你必须知道的JavaScript 中字符串连接的性能的一些问题
2013/05/07 Javascript
Javascript 赋值机制详解
2014/11/23 Javascript
详谈jQuery操纵DOM元素属性 attr()和removeAtrr()方法
2015/01/22 Javascript
javascript断点调试心得分享
2016/04/23 Javascript
Javascript中作用域的详细介绍
2016/10/06 Javascript
详解Html a标签中href和onclick用法、区别、优先级别
2017/01/16 Javascript
jquery对象与DOM对象转化
2017/02/08 Javascript
详解vue与后端数据交互(ajax):vue-resource
2017/03/16 Javascript
Vue2.0结合webuploader实现文件分片上传功能
2018/03/09 Javascript
JS中promise化微信小程序api
2018/04/12 Javascript
vue+vue-router转场动画的实例代码
2018/09/01 Javascript
详解如何创建并发布一个 vue 组件
2018/11/08 Javascript
Angular7.2.7路由使用初体验
2019/03/01 Javascript
javascript canvas API内容整理
2020/02/16 Javascript
Vue中父子组件的值传递与方法传递
2020/09/28 Javascript
[03:05]《我与DAC》之xiao8:DAC与BG
2018/03/27 DOTA
Python threading多线程编程实例
2014/09/18 Python
Python读写文件方法总结
2015/06/09 Python
Python实现矩阵转置的方法分析
2017/11/24 Python
python中的二维列表实例详解
2018/06/19 Python
Python字符串、整数、和浮点型数相互转换实例
2018/08/04 Python
Python拼接字符串的7种方法总结
2018/11/01 Python
使用Python轻松完成垃圾分类(基于图像识别)
2019/07/09 Python
Python 使用list和tuple+条件判断详解
2019/07/30 Python
html5中如何将图片的绝对路径转换成文件对象
2018/01/11 HTML / CSS
canvas绘图按照contain或者cover方式适配并居中显示
2019/02/18 HTML / CSS
公安纪律作风整顿剖析材料
2014/10/10 职场文书
小学教师师德培训心得体会
2016/01/09 职场文书
Go语言-为什么返回值为接口类型,却返回结构体
2021/04/24 Golang
maven依赖的version声明控制方式
2022/01/18 Java/Android