/** * Init. * @return void */ protected static function init() { // Start file. $backtrace = debug_backtrace(); self::$_startFile = $backtrace[count($backtrace) - 1]['file']; // Pid file. if (empty(self::$pidFile)) { self::$pidFile = __DIR__ . "/../" . str_replace('/', '_', self::$_startFile) . ".pid"; } // Log file. if (empty(self::$logFile)) { self::$logFile = __DIR__ . '/../workerman.log'; } touch(self::$logFile); chmod(self::$logFile, 0622); // State. self::$_status = self::STATUS_STARTING; // For statistics. self::$_globalStatistics['start_timestamp'] = time(); self::$_statisticsFile = sys_get_temp_dir() . '/workerman.status'; // Process title. self::setProcessTitle('WorkerMan: master process start_file=' . self::$_startFile); // Init data for worker id. self::initId(); // Timer init. Timer::init(); }
/** * 初始化一些环境变量 * @return void */ public static function init() { // 如果没设置$pidFile,则生成默认值 if (empty(self::$pidFile)) { $backtrace = debug_backtrace(); self::$_startFile = $backtrace[count($backtrace) - 1]['file']; self::$pidFile = sys_get_temp_dir() . "/workerman." . str_replace('/', '_', self::$_startFile) . ".pid"; } // 没有设置日志文件,则生成一个默认值 if (empty(self::$logFile)) { self::$logFile = __DIR__ . '/../workerman.log'; } // 标记状态为启动中 self::$_status = self::STATUS_STARTING; // 启动时间戳 self::$_globalStatistics['start_timestamp'] = time(); // 设置status文件位置 self::$_statisticsFile = sys_get_temp_dir() . '/workerman.status'; // 尝试设置进程名称(需要php>=5.5或者安装了proctitle扩展) self::setProcessTitle('WorkerMan: master process start_file=' . self::$_startFile); // 初始化定时器 Timer::init(); }