监控进程

webman自带一个monitor监控进程,它支持两个功能

  1. 监控文件更新并自动reload载入新的业务代码(一般在开发时使用)
  2. 监控所有进程占用内存,如果某个进程占用内存即将超过php.inimemory_limit限制则自动安全重启该进程(不影响业务)

监控配置

配置文件 config/process.phpmonitor配置


global $argv;

return [
    // File update detection and automatic reload
    'monitor' => [
        'handler' => process\Monitor::class,
        'reloadable' => false,
        'constructor' => [
            // Monitor these directories
            'monitorDir' => array_merge([    // 哪些目录下的文件需要被监控
                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 === '/', // 是否开启文件监控
                'enable_memory_monitor' => DIRECTORY_SEPARATOR === '/',                      // 是否开启内存监控
            ]
        ]
    ]
];

monitorDir用来配置监控哪些目录的更新(监控目录的文件不宜过多)。
monitorExtensions用来配置monitorDir目录里哪些文件后缀应该被监控。
options.enable_file_monitor值为true时,则开启文件更新监控(linux系统下以debug方式运行默认开启文件监控)。
options.enable_memory_monitor值为true时,则开启内存占用监控(内存占用监控不支持windows系统)。

提示
windows系统下当需要运行windows.bat 或者 php windows.php 时才能开启文件更新监控。

编辑于2024-03-13 17:42:49 完善本页 +发起讨论
赞助商
QQ交流群 865805921