php / curl:删除用CURLOPT_COOKIEJAR创建的cookie

时间:2011-12-12 12:57:13

标签: php cookies curl

大多数php / curl示例建议创建curl cookie,我使用一个来抓取网页。 这是脚本http://www.php.net/manual/en/ref.curl.php#93163,这里是相关的摘录:

$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 3 GB由php创建的curl cookie文件。

我认为这是自动清除的,是否可以从php / curl执行此操作?

2 个答案:

答案 0 :(得分:5)

首先必须是unset,然后是 $ ch ,然后你应该调用@unlink命令。

答案 1 :(得分:-1)

您可以delete个文件。