简体   繁体   English

在Symfony2路由之前进行重定向

[英]Redirecting before Symfony2 routing

I'm developing a high-traffic/high-seo-focused web. 我正在开发一个流量高/关注度高的网站。 Now we're doing redirects just at the beggining of the actions but it's a bit slow. 现在,我们只是在操作开始时才进行重定向 ,但是它有点慢。

Is there a way to hook before the routing and do the redirect there (we've do a Redis query in order to know if the URL is a 301 or not)? 有没有一种方法可以在路由之前挂接并在那里进行重定向(我们已经进行了Redis查询,以便知道URL是否为301)? Maybe the way is doing it just before even Symfony. 也许是在Symfony 之前就这样做了。

当然可以,创建一个优先级高于32(这是路由器侦听器的优先级)的侦听器,然后从那里重定向:

$response = new RedirectResponse($url);

$event->setResponse($response);

You really do need to provide much more information, there are a couple of things I see. 您确实确实需要提供更多信息,我发现了几件事。

First and foremost, please profile your app, there is a very nice tool called Blackfire that is made by the same company that makes Symfony. 首先,请分析您的应用程序,这是一个非常好的工具,称为Blackfire,它是由生产Symfony的同一家公司生产的。 With this you can pinpoint exactly where the performance bottleneck is, without it, we can only guess for example. 有了它,您可以精确地确定性能瓶颈在哪里,没有它,我们只能举例。

Could it be the query is taking too long, if so then optimize it. 可能是查询花费的时间太长,如果是,则对其进行优化。

Could it be network latency? 可能是网络延迟吗? Maybe you have a cluster of servers where a user does a DNS lookup, which accesses a server is the US but then you redirect him to a different site leading to a different DNS lookup to a server in Europe or something of the sort. 也许您有一个服务器集群,用户在其中进行DNS查找,而该服务器访问的是美国服务器,但随后您将其重定向到另一个站点,从而导致对欧洲某类服务器进行不同的DNS查找。

At last, could it be Symfony and Php itself? 最后,可能是Symfony和Php本身吗? In that case, I would recommend looking at connecting your webserver directly to Redis for example Nginx or Varnish for example 在这种情况下,建议您将网络服务器直接连接到Redis,例如Nginx或Varnish。

https://github.com/openresty/redis2-nginx-module#readme https://github.com/openresty/redis2-nginx-module#readme

and

https://www.varnish-cache.org/vmod/redis https://www.varnish-cache.org/vmod/redis

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

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