Closing PHP/CURL Sessions

You should close a PHP/CURL session immediately after you are done using it, as shown in Example A-23. Closing the PHP/CURL session frees up server resources, primarily memory.

Example A-23. Closing a PHP/CURL session

curl_close($s);

In normal use, PHP performs garbage collection, freeing resources like variables, socket connections, and memory when the script completes. This works fine for scripts that control web pages and execute quickly. However, webbots and spiders may require that PHP scripts run for extended periods without garbage collection. (I’ve written webbot scripts that run for many months without stopping.) Closing each PHP/CURL session is imperative if you’re writing webbot and spider scripts that make many ...

Get Webbots, Spiders, and Screen Scrapers, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.