/**
  * 从消息队列中获取要监控的文件列表
  * @param bool $block
  * @return void
  */
 protected function collectFiles($block = false)
 {
     $msg_type = $message = null;
     $flag = $block ? 0 : MSG_IPC_NOWAIT;
     if (@msg_receive(\Man\Core\Master::getQueueId(), self::MSG_TYPE_FILE_MONITOR, $msg_type, 10000, $message, true, $flag)) {
         // 被排除的路径
         $exclude_path = array();
         // 因为配置可能会被更改,所以每次都会重新从配置中查找排除路径
         $config_exclude_path = $this->getExcludeFiles();
         foreach ($config_exclude_path as $path) {
             if ($real_path = realpath($path)) {
                 $exclude_path[] = $real_path;
             }
         }
         foreach ($message as $file) {
             $is_exclude_file = false;
             foreach ($exclude_path as $path) {
                 // 是被排除的文件
                 if (0 === strpos($file, $path)) {
                     $is_exclude_file = true;
                     break;
                 }
             }
             if (!$is_exclude_file && !isset($this->filesToInotify[$file])) {
                 $stat = @stat($file);
                 $mtime = isset($stat['mtime']) ? $stat['mtime'] : 0;
                 $this->filesToInotify[$file] = $mtime;
             }
         }
     }
 }
Example #2
0
 /**
  * 从消息队列中获取要监控的文件列表
  * @param bool $block
  * @return void
  */
 protected function collectFiles($block = false)
 {
     $msg_type = $message = null;
     $flag = $block ? 0 : MSG_IPC_NOWAIT;
     if (msg_receive(\Man\Core\Master::getQueueId(), self::MSG_TYPE_FILE_MONITOR, $msg_type, 10000, $message, true, $flag)) {
         foreach ($message as $file) {
             if (!isset($this->filesToInotify[$file])) {
                 $stat = @stat($file);
                 $mtime = isset($stat['mtime']) ? $stat['mtime'] : 0;
                 $this->filesToInotify[$file] = $mtime;
             }
         }
     }
 }
Example #3
0
 /**
  * 开发环境将当前进程使用的文件写入消息队列,用于FileMonitor监控文件更新
  * @return void
  */
 protected function writeFilesListToQueue()
 {
     if (!Master::getQueueId()) {
         return;
     }
     $error_code = 0;
     $flip_file_list = array_flip(get_included_files());
     $file_list = array_diff_key($flip_file_list, $this->includeFiles);
     $this->includeFiles = $flip_file_list;
     if ($file_list) {
         foreach (array_chunk($file_list, 10, true) as $list) {
             msg_send(Master::getQueueId(), self::MSG_TYPE_FILE_MONITOR, array_keys($list), true, false, $error_code);
         }
     }
 }
Example #4
0
 /**
  * 从消息队列中获取主进程状态
  * @return void
  */
 protected function getStatusFromQueue()
 {
     if (@msg_receive(\Man\Core\Master::getQueueId(), self::MSG_TYPE_STATUS, $msg_type, 10000, $message, true, MSG_IPC_NOWAIT)) {
         $pid = $message['pid'];
         $worker_name = $message['worker_name'];
         $address = \Man\Core\Lib\Config::get($worker_name . '.listen');
         if (!$address) {
             $address = '';
         }
         $str = "{$pid}\t" . str_pad(round($message['memory'] / (1024 * 1024), 2) . "M", 7) . " " . str_pad($address, $this->maxAddressLength) . " " . $message['start_time'] . " " . str_pad($worker_name, $this->maxWorkerNameLength) . " ";
         if ($message) {
             $str = $str . str_pad($message['total_request'], 14) . " " . str_pad($message['packet_err'], 10) . " " . str_pad($message['thunder_herd'], 12) . " " . str_pad($message['client_close'], 12) . " " . str_pad($message['send_fail'], 9) . " " . str_pad($message['throw_exception'], 15) . " " . ($message['total_request'] == 0 ? 100 : round(($message['total_request'] - ($message['packet_err'] + $message['send_fail'])) / $message['total_request'], 6) * 100) . "%";
         } else {
             $str .= var_export($message, true);
         }
         $this->sendToClient($str . "\n");
         return true;
     }
     return false;
 }
Example #5
0
 /**
  * 将当前worker进程状态写入消息队列
  * @return void
  */
 protected function writeStatusToQueue()
 {
     if (!Master::getQueueId()) {
         return;
     }
     $error_code = 0;
     @msg_send(Master::getQueueId(), self::MSG_TYPE_STATUS, array_merge($this->statusInfo, array('memory' => memory_get_usage(true), 'pid' => posix_getpid(), 'worker_name' => $this->workerName)), true, false, $error_code);
 }