I've figured out, that it's quite easy to purge a ressource out of Varnish Cache by using php_exec
. Regarding to the available libraries, like php-varnish, this method is quite comfortable.
exec('curl -X PURGE http://www.mysite.com/helloworld.html')
What's the fastest curl solution and what are the security arrangements of using curl with varnish ?
curl_setopt($fp, CURLOPT_URL, "http://www.mysite.com/helloworld.html");
curl_setopt($fp, CURLOPT_HEADER, 1);
curl_setopt($fp, CURLOPT_RETURNTRANSFER, false);
curl_setopt($fp, CURLOPT_TIMEOUT, 1000);
curl_setopt($fp, CURLOPT_CONNECTTIMEOUT, 1000);
curl_setopt($fp, CURLOPT_REFERER, "http://www.mysite.com");
curl_setopt( CURLOPT_HTTPHEADER, "PURGE");
The answer is simple : error handling.
Using system curl command will return limited error messages that you will have to handle the dirty way.
PHP-curl will return accurate error codes and messages that you can easily handle.
Another thing is that with your first option, you depend on your environment and it will be hard to see that system curl is not available.
Using php curl command will tell you exactly "I don't know curl_setopt function" if it's not installed.
Last thing is that you don't need to set all these curl options. Varnish doesn't need any referrer to handle purge.