php / curl: delete cookie created with CURLOPT_COOKIEJAR

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



php / curl: delete cookie created with CURLOPT_COOKIEJAR



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 Answers
2



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


unset


@unlink





I had this exact same problem, and found I couldn't unlink the files. After some experimentation, I found that curl_close($ch) had to be called before you called unlink() to delete the cookie jar file. Perhaps unset($ch) causes the curl handle to be closed as well?
– Josh
Feb 27 '13 at 16:18






@Josh thank for this command: curl_close($ch)
– vuhung3990
Oct 30 '14 at 5:11



You could delete the files.





But you can only delete the files after calling curl_close($ch). Yousha Aleayoub reports in his answer that unset($ch) will also allow them to be deleted.
– Josh
Feb 27 '13 at 16:20






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard