简体   繁体   English

PHP 5.5 FastCGI缓存

[英]PHP 5.5 FastCGI Caching

I've implemented FastCGI caching on our site, and have seen great speed improvements. 我在我们的网站上实现了FastCGI缓存,并且已经看到了极大的速度提升。 However the FastCGI cache key does not seem to be unique enough. 但是,FastCGI缓存键似乎不够独特。 If I login, my name appears in the header. 如果我登录,我的名字会出现在标题中。 However the next person to login still sees my name in the header, assuming the cache is still valid. 但是,下一个登录的人仍然会在标题中看到我的名字,假设缓存仍然有效。

Is there a way to make the cache key unique on a per-user basis? 有没有办法使缓存密钥在每个用户的基础上是唯一的? Ideally using a unique identifier from the user's Cookies or a PHP Session? 理想情况下使用用户的Cookie或PHP会话中的唯一标识符? I tried implemented the answer below, but Nginx failed to restart. 我尝试实现下面的答案,但Nginx无法重启。

Log in value from Set-Cookie header in nginx 从nginx中的Set-Cookie标头登录值

Note my cache key looks like this: 请注意我的缓存键如下所示:

fastcgi_cache_key "$scheme$request_method$host$request_uri";

Update: My thought is if I can parse the HTTP headers sent to Nginx, then I can grab the PHP SESSION ID and use that. 更新:我的想法是,如果我可以解析发送到Nginx的HTTP标头,那么我可以获取PHP SESSION ID并使用它。 However I cannot find an example of how to do this anywhere. 但是,我无法找到如何在任何地方执行此操作的示例。 Right now I have something like this, which doesn't work. 现在我有这样的东西,这是行不通的。

http_cookie ~* PHPSESSID=([0-9a-z]+) {
    set $ses_id $1;
}

I was able to solve the above problem using the Nginx ngx_http_userid_module . 我能够使用Nginx ngx_http_userid_module解决上述问题。 The hardest part was actually finding the module, implementing the solution was quite trivial. 最困难的部分实际上是找到模块,实施解决方案非常简单。

I used their example configuration: 我使用了他们的示例配置:

userid         on;
userid_name    uid;
userid_domain  example.com;
userid_path    /;
userid_expires 365d;
userid_p3p     'policyref="/w3c/p3p.xml", CP="CUR ADM OUR NOR STA NID"';

And then added the userid to my fastCGI cache key: 然后将userid添加到我的fastCGI缓存键:

fastcgi_cache_key "$scheme$request_method$host$request_uri$uid_got";

Hopefully this answer helps someone discover this useful module quicker than I did. 希望这个答案可以帮助别人比我更快地发现这个有用的模块。

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

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