Process Monitoring

Webman comes with a built-in monitor process that supports two functions:

  1. Monitoring file updates and automatically reloading new business code (generally used during development).
  2. Monitoring memory usage of all processes; if a process's memory usage is about to exceed the memory_limit set in php.ini, it will safely restart that process automatically (without affecting the business).

Monitoring Configuration

Configuration file config/process.php contains the monitor settings.


global $argv;

return [
    // File update detection and automatic reload
    'monitor' => [
        'handler' => process\Monitor::class,
        'reloadable' => false,
        'constructor' => [
            // Monitor these directories
            'monitorDir' => array_merge([    // The directories whose files need to be monitored
                app_path(),
                config_path(),
                base_path() . '/process',
                base_path() . '/support',
                base_path() . '/resource',
                base_path() . '/.env',
            ], glob(base_path() . '/plugin/*/app'), glob(base_path() . '/plugin/*/config'), glob(base_path() . '/plugin/*/api')),
            // Files with these suffixes will be monitored
            'monitorExtensions' => [
                'php', 'html', 'htm', 'env'
            ],
            'options' => [
                'enable_file_monitor' => !in_array('-d', $argv) && DIRECTORY_SEPARATOR === '/', // Whether to enable file monitoring
                'enable_memory_monitor' => DIRECTORY_SEPARATOR === '/',                      // Whether to enable memory monitoring
            ]
        ]
    ]
];

monitorDir is used to configure which directories to monitor for updates (the number of files in the monitored directories should not be excessive).
monitorExtensions is used to configure which file suffixes in the monitorDir directories should be monitored.
When the value of options.enable_file_monitor is true, file update monitoring is enabled (in Linux systems, file monitoring is enabled by default when running in debug mode).
When the value of options.enable_memory_monitor is true, memory usage monitoring is enabled (memory usage monitoring is not supported on Windows systems).

Tip
On Windows systems, file update monitoring can only be enabled when running windows.bat or php windows.php.