Couldn't find this info in google or by asking people in discord programming servers. Before I ask the main question I wanna confirm something first:
When java runs in tomcat, lets say like in case of Spring Boot application with Tomcat built in it:
- all the components managed by ioc container: @controller/@configuration/@service, and other annotations that indicate that class should be managed by the container, do all these components get instantiated in container on startup of the application, before any http request comes from the client ? All the different controllers for many different, routes, do they get instantiated before they are actually needed to process any request ?
- if so, do all these instances of these components get used to process all subsequent incoming requests ? like a controller instance wouldnt be destroyed by GC after a request was processed and response was returned to client ? this controller is always kept in memory(heap I guess) until application stops running ?
- when a new http request comes to tomcat from client, does some new thread get created to process this request ? does this thread use the same instance of controller and other components managed by container to process the request ?
Now main question.
In PHP the whole new process is started when server starts index.php file and passes the request to it to process it. And php programs also have ioc containers, PDOs, repositories, etc - the components that are manage by container. Container can be self made by developers or provided by FW like symfony, laminas, laravel.
Does this mean that whenever a request is processed by PHP program, all the possible controllers get instantiated in IOC container, get their dependencies injected, but since requests usually need just 1 controller to be processed, all the other controllers and components that got created on startup of app and IOC container, they got just created for nothing, got never used, and then app just died without doing anything with those unused controllers/components, except the 1 controller that was matched by the route of the request ?