简体   繁体   English

清漆缓存+ PHP

[英]Varnish Cache + PHP

I've figured out, that it's quite easy to purge a ressource out of Varnish Cache by using php_exec . 我发现,使用php_exec 从Varnish Cache中清除资源非常容易。 Regarding to the available libraries, like php-varnish , this method is quite comfortable. 对于可用的库,例如php-varnish ,此方法相当舒适。

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. 使用系统curl命令将返回有限的错误消息,您必须处理这些错误消息。

PHP-curl will return accurate error codes and messages that you can easily handle. PHP-curl将返回准确的错误代码和消息,您可以轻松地处理它们。

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. 另一件事是,使用第一个选项时,您将取决于您的环境,并且很难看到系统curl不可用。

Using php curl command will tell you exactly "I don't know curl_setopt function" if it's not installed. 如果未安装,使用php curl命令将告诉您“我不知道curl_setopt函数”。

Last thing is that you don't need to set all these curl options. 最后一件事是您不需要设置所有这些curl选项。 Varnish doesn't need any referrer to handle purge. Varnish不需要任何引用程序即可进行清除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM