PHP CURL 内存泄露问题解决方法

 更新时间:2015年02月12日 11:35:19   投稿:junjie  
这篇文章主要介绍了PHP CURL 内存泄露问题解决方法,CRUL长时间访问HTTPS网站时有内存泄露问题,本文经过反复调试找到了解决方法,需要的朋友可以参考下

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函数mkdir实现递归创建层级目录

    php函数mkdir实现递归创建层级目录

    当我们想在自己的站点中添加多级目录时,可以运用php函数mkdir()来实现这个功能。具有一定的参考价值,感兴趣的小伙伴们可以参考一下。
    2016-10-10
  • CI框架开发新浪微博登录接口源码完整版

    CI框架开发新浪微博登录接口源码完整版

    说明:本贴只适合CI框架。功能实现:登录接口跳转链接成功,获取用户信息(包括最重要的u_id)成功,将用户于本地平台连接起来,用户登录成功后信息的存储,本地数据库第三方登录表的设计。总之接口流程已全部完成。每个关键步骤我几乎都有注释,讲解详细。
    2014-05-05
  • Laravel核心解读之异常处理的实践过程

    Laravel核心解读之异常处理的实践过程

    这篇文章主要给大家介绍了关于Laravel核心解读之异常处理的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
    2019-02-02
  • Laravel统一封装接口返回状态实例讲解

    Laravel统一封装接口返回状态实例讲解

    这篇文章主要介绍了Laravel统一封装接口返回状态实例讲解,封装接口返回状态有利于前后端分离项目的合作开发,有正好需要的同学可以研究下
    2021-03-03
  • thinkPHP3.0框架实现模板保存到数据库的方法

    thinkPHP3.0框架实现模板保存到数据库的方法

    这篇文章主要介绍了thinkPHP3.0框架实现模板保存到数据库的方法,结合实例形式分析了使用thinkPHP3.0框架开发CMS系统过程中将模板保存到数据库的具体实现步骤与相关操作技巧,需要的朋友可以参考下
    2017-08-08
  • php curl登陆qq后获取用户信息时证书错误

    php curl登陆qq后获取用户信息时证书错误

    这篇文章主要介绍了php curl登陆qq后获取用户信息时证书错误,需要的朋友可以参考下
    2015-02-02
  • destoon实现调用热门关键字的方法

    destoon实现调用热门关键字的方法

    这篇文章主要介绍了destoon实现调用热门关键字的方法,对于进行模板开发来说非常有用,需要的朋友可以参考下
    2014-07-07
  • PHP面试常用算法(推荐)

    PHP面试常用算法(推荐)

    下面小编就为大家带来一篇PHP面试常用算法(推荐)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2016-07-07
  • thinkphp5.1 框架导入/导出excel文件操作示例

    thinkphp5.1 框架导入/导出excel文件操作示例

    这篇文章主要介绍了thinkphp5.1 框架导入/导出excel文件操作,结合实例形式分析了thinkphp5.1 框架导入/导出excel文件具体操作实现技巧与相关注意事项,需要的朋友可以参考下
    2020-05-05
  • Laravel 5.5基于内置的Auth模块实现前后台登陆详解

    Laravel 5.5基于内置的Auth模块实现前后台登陆详解

    最近在使用laravel5.5,利用其实现了一个功能,下面分享给大家,这篇文章主要给大家介绍了关于Laravel 5.5基于内置的Auth模块如何实现前后台登陆的相关资料,文中通过示例代码介绍的非常详细,需要的朋友可以参考借鉴,下面随着小编来一起学习学习吧。
    2017-12-12

最新评论