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

gio*_*o79 2 php cookies curl

大多数php/curl示例建议创建curl cookie,我使用一个来抓取web.这是脚本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 );
Run Code Online (Sandbox Code Playgroud)

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

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

You*_*oub 5

首先必须是unset,然后$通道,然后你应该调用@unlink命令.

  • 我有这个完全相同的问题,发现我无法取消链接文件.经过一些实验,我发现在调用unlink()删除cookie jar文件之前必须调用curl_close($ ch).也许未设置($ ch)导致卷曲手柄也被关闭? (2认同)