[Symfony] app_dev.php profiler throws 404
https://stackoverflow.com/questions/16800692/symfony-404-not-found/34048364#34048364
https://stackoverflow.com/questions/16243746/starting-with-symfony-2-app-dev-php-works-app-php-404s
https://stackoverflow.com/questions/30336232/i-cant-access-to-my-web-site-symfony-you-are-not-allowed-to-access-this-file
https://stackoverflow.com/questions/16243746/starting-with-symfony-2-app-dev-php-works-app-php-404s
https://stackoverflow.com/questions/30336232/i-cant-access-to-my-web-site-symfony-you-are-not-allowed-to-access-this-file
According to my own experience; this behavior happens when you change the standard behavior of your routes. For example, in my case I was using kernel.request listener to create a language detection mechanism which supposed pick the best possible language for the user based on her/his browsers supported language.
I was using {_locale} prefix in all my routes located in app/config/routing.yml
some_route:
resource: "@MyBundle/Resources/config/routing.yml"
prefix: /{_locale}/
This way I was able to quickly add at the beginning of my routes the language code and in my listener class I was redirecting the client to a route prefixed with an existing language code regardless the client requested the route with or without the locale.
For example, if my site had only "en" and "de" as languages and if the user requested
http://www.mysite.com/somepage
or
http://www.mysite.com/fr/somepage
I was redirecting the client to
http://www.mysite.com/en/somepage
So whenever there was an error in my application the profiler route was unaware of this situation and was trying to show itself from a route that has no {_locale} prefixed. And this was causing a 404 error.
---
The solution was simple:
I opened the app/config/routing_dev.yml file and modified the all the routes as below:
_wdt:
resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml"
prefix: /{_locale}/_wdt
_profiler:
resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml"
prefix: /{_locale}/_profiler
_configurator:
resource: "@SensioDistributionBundle/Resources/config/routing/webconfigurator.xml"
prefix: /{_locale}/_configurator
Notice the /{_locale} part.
So the problem is fixed for me.
---
9
|
My problem was that
kernel.terminate event was executing for more than 10 seconds. It was very hard to spot, because profiler was not measuring timeline for this event.
When I realised this, I immediately narrowed the problem down to one of my event listeners having abnormally long running
__construct method. This delayed profile file printing for too long, which caused a Javascript timeout error after 5 retries.
After fixing the offending listener,
kernel.terminate event went fast and the problem was gone immediately.
You can quickly see your attached listeners using
bin/console debug:event-dispatcher kernel.terminate .
---
It's often problem with event subscriber/listener. Try run
And check for errors
https://stackoverflow.com/questions/16243746/starting-with-symfony-2-app-dev-php-works-app-php-404s
---
|
留言
張貼留言