I'm relatively new to Symfony. I am currently working on a prototype with Symfony & Docker.
Today I implemented an AuthenticationService via Login (like this: https://symfony.com/doc/current/security.html). When I now load my application, the server- response time is around 1500 ms. Without this authentication, the response time is around 70 ms.
I turned on the profiler, and it seems that the "TraceableFirewallListener" takes a lot of time. Symfony Profiler Result I already tried the comman tipps (changing to prod env, disabeling debug).
I don't really have a clue why it is taking that long, but I'm pretty sure that this can't be normal. I also do not want to implement the "solution" from here (TraceableFirewallListener extremely long loading time), since this seems a very bad practice for me.
My security.yaml is below. If you need anything else, please ask me and I will attatch it.
Thanks for the help in advance
UPDATE
Installed blackfire and found some interesting graphs, maybe this will help: https://blackfire.io/profiles/197c3e1c-c53b-4c28-b793-a384fdb90755/graph
security:
encoders:
App\Entity\User:
algorithm: auto
providers:
app_user_provider:
entity:
class: App\Entity\User
property: email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: lazy
provider: app_user_provider
guard:
authenticators:
- App\Security\LoginFormAuthenticator
logout:
path: app_logout
access_control:
- { path: ^/login$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
Why is my response time so long? And how do I make it shorter?
Turns out, it had nothing to to with the Authenticator itself at all. Symfony was not able to use the cache at all, which led to a reconsructing/ rebuilding of the LoginFormAuthenticator every request. The long response time in this case is probably due to the fact that for this service a lot of classes are used and every single one of them is recreated.
The fix for me was 1. adding the 'var' folder to the .dockerignore, so the directory was not copied to the container while building. Secondly I had to remove the mount for the complete 'app' folder (which contained the 'var' folder and the cache inside of it). Dont forget to "remount" the necessary folders. I think the reason why this issue happened in the first place was, I did created the symfony project on my host machine and thought everything has to be inside the container. Seems that this led to no permission for using the cache.
Response times back to ~70 ms