php / curl:删除用CURLOPT_COOKIEJAR创建的cookie [英] php / curl: delete cookie created with CURLOPT_COOKIEJAR

查看:263
本文介绍了php / curl:删除用CURLOPT_COOKIEJAR创建的cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大多数php / curl示例建议创建curl cookie,并且我正在使用一个来抓取网络。
以下是脚本 http://www.php.net /manual/en/ref.curl.php#93163 ,以下是相关节选:

Most php / curl samples recommend creating curl cookies, and I am using one to crawl the web. Here is the script http://www.php.net/manual/en/ref.curl.php#93163 and here is the relevant excerpt:

$url = str_replace( "&", "&", urldecode(trim($url)) );

$cookie = tempnam ("/tmp", "CURLCOOKIE");
$ch = curl_init();
curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1" );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookie );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_ENCODING, "" );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );    # required for https urls
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );
curl_setopt( $ch, CURLOPT_TIMEOUT, $timeout );
curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 );
$content = curl_exec( $ch );
$response = curl_getinfo( $ch );
curl_close ( $ch );

现在我注意到/ tmp由php创建的3 GB curl cookie文件。

Now I noticed in /tmp 3 GB of curl cookie files created by php.

我的印象是这是自动清除,是否可以从php / curl做到这一点?

I was under the impression this is cleared automatically, is it possible to do this from php / curl?

推荐答案

首先必须取消设置,然后 $ ch ,然后调用 @unlink 命令。

First must be unset, then $ch and then call @unlink command.

这篇关于php / curl:删除用CURLOPT_COOKIEJAR创建的cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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