Execution Flow
Process Startup Flow
When executing php start.php start
, the execution flow is as follows:
- Load the configurations under the config/ directory.
- Set the relevant configurations for the Worker, such as
pid_file
,stdout_file
,log_file
,max_package_size
, etc. - Create the webman process and start listening 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 the
onWorkerStart
method):
① Load the files set inconfig/autoload.php
, such asapp/functions.php
.
② Load the middlewares set inconfig/middleware.php
(includingconfig/plugin/*/*/middleware.php
).
③ Execute thestart
method of the classes set inconfig/bootstrap.php
(includingconfig/plugin/*/*/bootstrap.php
) for initializing some modules, such as Laravel database connection.
④ Load the routes defined inconfig/route.php
(includingconfig/plugin/*/*/route.php
).
Request Handling Flow
- Check if the requested URL corresponds to a static file under the public directory. If yes, return the file (end of the request). If not, proceed to step 2.
- Determine if the URL matches a certain route. If not matched, proceed to step 3. If matched, proceed to step 4.
- Check if the default route is disabled. If yes, return 404 (end of the request). If not, proceed to step 4.
- Find the middlewares for the requested controller, execute the middleware pre-operations in order (onion model request phase), execute the controller's business logic, execute the middleware post-operations (onion model response phase), and conclude the request (refer to Middleware Onion Model).