一次或频繁执行curl_close()之间的区别? [英] difference between executing curl_close() once or frequently?

查看:94
本文介绍了一次或频繁执行curl_close()之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



为什么我问这个问题,很简单,因为有人告诉我,PHP垃圾收集器完成了所有这些操作,有时不需要关闭数据库连接或调用 __ destruct 方法来释放资源。



自从那一刻起,我实际上开始考虑应该在哪里调用它呢?目前,我对这个问题很感兴趣,因为我编写了一个用于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 __destruct 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天全站免登陆