duandaijian1583 2011-12-12 12:57
浏览 143
已采纳

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

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 );

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

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

  • 写回答

2条回答 默认 最新

  • donglao9606 2012-08-28 22:43
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?