Пример #1
0
 /**
  * 心跳
  * @param NodeInfo $nodeInfo
  * @param array $req
  */
 protected function _udp_heartbeat($nodeInfo, $req)
 {
     //更新心跳时间
     $nodeInfo->hearbeatTime = time();
     $this->log("heartbeat, node=" . $nodeInfo->address . ", version=" . $nodeInfo->version);
     //信息过期了需要更新
     if ($nodeInfo->updateTime < $nodeInfo->hearbeatTime - $this->nodeInfoLifeTime) {
         $nodeInfo->send(['cmd' => 'getInfo']);
         return;
     }
     //没有版本号
     if (empty($nodeInfo->version)) {
         $this->log($nodeInfo->address . " version is null");
     } elseif (String::versionCompare($this->nodeCurrentVersion['version'], $nodeInfo->version) > 0) {
         $nodeInfo->send(['cmd' => 'upgrade', 'url' => $this->nodeCurrentVersion['url'], 'hash' => $this->nodeCurrentVersion['hash'], 'version' => $this->nodeCurrentVersion['version']]);
         $this->log($nodeInfo->address . " upgrade to {$this->nodeCurrentVersion['version']}");
     }
 }
Пример #2
0
 /**
  * 传输文件
  * @param $fd
  * @param $_data
  */
 protected function transportFile($fd, $_data)
 {
     //直接接收数据,不需要解析json
     $data = $this->unpack($_data, false);
     $info =& $this->files[$fd];
     $fp = $info['fp'];
     $file = $info['file'];
     if (!fwrite($fp, $data)) {
         $this->sendResult($fd, 600, "fwrite failed. transmission stop.");
         //关闭文件句柄
         fclose($this->files[$fd]['fp']);
         unlink($file);
     } else {
         $info['recv'] += strlen($data);
         if ($info['recv'] >= $info['size']) {
             $this->sendResult($fd, 0, "Success, transmission finish. Close connection.");
             //关闭句柄
             fclose($this->files[$fd]['fp']);
             unset($this->files[$fd]);
         }
     }
     //上传到脚本目录,自动增加执行权限
     if (Swoole\String::startWith($file, $this->script_path)) {
         chmod($file, 0777);
     }
 }