workerman error reporting 的坑
24 August 2018

部署了 workerman 来作为 rabbitmq 的 consumer,发现日志量剧增,看了下是 error_reporting 的问题。workerman 的 worker 默认的 error_reporting 是 E_ALL ,在下面的文件中

./vendor/workerman/workerman/Lib/Constants.php

// Display errors.
ini_set('display_errors', 'on');

// Reporting all.
error_reporting(E_ALL);

所以要这样来解决

// 修改错误级别
$parent_error_reporting = error_reporting();

Worker::$stdoutFile = "xxx";
Worker::$logFile = "xxx";
Worker::$daemonize = true;
$worker = new Worker();
$worker->onWorkerStart = function (Worker $worker) use ($parent_error_reporting) {
    error_reporting($parent_error_reporting);
    // ...
};
Worker::runAll();