Execution Flow
Process Startup Flow
When executing php start.php start, the execution flow is as follows:
- Load the configurations under config/
- Set 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: 8787)
- Create custom processes based on the configuration
- After the webman process and custom processes are started, the following logic is executed (all within
onWorkerStart):
① Load the files set inconfig/autoload.php, such asapp/functions.php
② Load the middlewares set inconfig/middleware.php(includingconfig/plugin/*/*/middleware.php)
③ Execute thestartmethod of the classes set inconfig/bootstrap.php(includingconfig/plugin/*/*/bootstrap.php) for initializing modules, such as Laravel database connection
④ Load the routes defined inconfig/route.php(includingconfig/plugin/*/*/route.php)
Request Handling Flow
- Check if the request URL corresponds to a static file under public. If yes, return the file (end of request). If not, proceed to step 2.
- Determine whether the URL matches a route. If not matched, proceed to step 3; if matched, proceed to step 4.
- Check whether the default route is disabled. If yes, return 404 (end of request). If not, proceed to step 4.
- Find the middlewares for the requested controller, execute middleware pre-operations in order (onion model request phase), execute the controller's business logic, execute middleware post-operations (onion model response phase), and conclude the request. (See Middleware Onion Model)