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)? Maybe the way is doing it just before even Symfony.
2
Answers
Sure you can, create a listener with a priority higher than 32 (which is the router listener’s priority) and then redirect from there:
$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. 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.
At last, could it be Symfony and Php itself? In that case, I would recommend looking at connecting your webserver directly to Redis for example Nginx or Varnish for example
https://github.com/openresty/redis2-nginx-module#readme
and
https://www.varnish-cache.org/vmod/redis