Execution Flow
Process Startup Flow
The execution flow after running php start.php start
is as follows:
- Load the configurations from the
config/
directory. - Set up Worker-related configurations such as
pid_file
,stdout_file
,log_file
,max_package_size
, etc. - Create the webman process and listen on the port (default is 8787).
- Create custom processes based on the configuration.
- After the webman process and custom processes start, the following logic is executed (all executed within
onWorkerStart
):
① Load files set inconfig/autoload.php
, such asapp/functions.php
.
② Load middleware defined inconfig/middleware.php
(includingconfig/plugin/*/*/middleware.php
).
③ Execute thestart
method of the classes defined inconfig/bootstrap.php
(includingconfig/plugin/*/*/bootstrap.php
) to initialize some modules, such as Laravel database initialization connections.
④ Load the routes defined inconfig/route.php
(includingconfig/plugin/*/*/route.php
).
Request Handling Flow
- Determine whether the requested URL corresponds to a static file under the
public
directory. If it does, return the file (end the request); if not, proceed to step 2. - Check if the URL matches a specific route. If not matched, proceed to step 3; if matched, proceed to step 4.
- Check if the default route is disabled. If it is, return 404 (end the request); if not, proceed to step 4.
- Find the middleware corresponding to the requested controller, execute the middleware's before actions in order (onion model request phase), execute the business logic of the controller, and execute the middleware's after actions (onion model response phase), ending the request. (Refer to Middleware Onion Model)