PHP,Curl,curl_exec(),curl_close()和cookie [英] PHP, Curl, curl_exec(), curl_close() and cookies

查看:304
本文介绍了PHP,Curl,curl_exec(),curl_close()和cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Curl中使用PHP时,需要在每次调用curl_exec()后调用curl_close()才能使用CURLOPT_COOKIEJAR和CURLOPT_COOKIEFILE选项正确地使Cookie正常工作?或者我可以调用curl_exec()多次,因为我喜欢不同的urls在同一个网站,仍然有cookie保持没有调用curl_close()之后每一个?

When using PHP with Curl is it necessary to call curl_close() after every call to curl_exec() for cookies to function properly using the CURLOPT_COOKIEJAR AND CURLOPT_COOKIEFILE options? Or can I call curl_exec() as many times as I like to different urls on the same site and still have the cookies maintained without calling curl_close() after each one? Can I use curl_exec() many times and just close it curl_close() at the end of the script?

推荐答案

您应该只能使用curl_exec调用 curl_close(),当你知道你已经完成了那个特定的句柄,或者如果从当前状态切换到一个新的(即:通过 curl_setopt()从一个干净的新句柄比当前的脏句柄更快。

You should only call curl_close() when you know you're done with that particular handle, or if switching from its current state to a new one (ie: changing a ton of options via curl_setopt() would be faster by going from a clean new handle than your current "dirty" one.

/文件选项只是严格地需要在单独的curl句柄/调用之间维护cookie,每个都独立于其他的,所以cookie文件是他们之间共享的唯一方式。

The cookiejar/file options are only strictly necessary for maintaining cookies between seperate curl handles/invokations. Each one's independent of the others, so the cookie files are the only way to share between them.

这篇关于PHP,Curl,curl_exec(),curl_close()和cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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