Execution Flow

Process Startup Flow

The execution flow after running php start.php start is as follows:

  1. Load the configurations from the config/ directory.
  2. Set up Worker-related configurations such as pid_file, stdout_file, log_file, max_package_size, etc.
  3. Create the webman process and listen on the port (default is 8787).
  4. Create custom processes based on the configuration.
  5. After the webman process and custom processes start, the following logic is executed (all executed within onWorkerStart):
    ① Load files set in config/autoload.php, such as app/functions.php.
    ② Load middleware defined in config/middleware.php (including config/plugin/*/*/middleware.php).
    ③ Execute the start method of the classes defined in config/bootstrap.php (including config/plugin/*/*/bootstrap.php) to initialize some modules, such as Laravel database initialization connections.
    ④ Load the routes defined in config/route.php (including config/plugin/*/*/route.php).

Request Handling Flow

  1. 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.
  2. Check if the URL matches a specific route. If not matched, proceed to step 3; if matched, proceed to step 4.
  3. Check if the default route is disabled. If it is, return 404 (end the request); if not, proceed to step 4.
  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)