使用CURL_CLOSE? [英] use CURL_CLOSE or not?

查看:184
本文介绍了使用CURL_CLOSE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

何时需要关闭curl连接并释放其所消耗的资源?



为什么要提出这个问题,很简单,因为我被告知PHP垃圾收集器做所有这些,有时没有必要关闭DB连接或调用 __ destuct 方法释放资源。



从那时起,我真的开始考虑我应该在哪里叫它呢?目前我对这个问题感兴趣,因为我写一个小的库curl,我想知道什么时候需要用户 curl_close()函数。 / p>

感谢大家的讨论和解释。

解决方案

据我所知。 GC仅清除不再使用/引用的资源。
当curl变量超出范围时,它将被清除。
但是这可能只有在脚本完成后,或者当会话被销毁时(取决于作用域)才会发生。



但是为了安全起见,只是遵循常识。当它不再需要时关闭它。


When is it necessary to close curl connection and release resources consumed by it?

Why do I ask this question, well quite simply because I was told, that PHP garbage collector does all of this and sometimes there is no need to close DB connection or call the __destuct method to release resources.

Since, that moment I actually started to think about where do I need to call it then? At the moment I'm interested with that question since I writing a small library for curl and I'd like to understand when do I need to user curl_close() function.

Thank you all for discussion and explanation of it.

解决方案

as far as i understand it. The GC only cleans up resources that are no longer used/referenced. as whenever the curl variable fall out of scope, it'll be cleaned up. But that might only happen after the script has finished, or whenever the session is destroyed (depending on scope).

But to be on the safe side, just follow common sense.. close it when its no longer needed.

这篇关于使用CURL_CLOSE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆