public function onReceive($serv, $fd, $from_id, $data)
{
$remote_info = json_decode($data, true);
//判断是否为二进制图片流
if (!is_array($remote_info)) {
if (isset($this->curpath['path'])) {
if (is_dir(dirname(MYPATH . $this->curpath['path'])) && is_readable(dirname(MYPATH . $this->curpath['path']))) {
} else {
mkdir(dirname(MYPATH . $this->curpath['path']), 0777, true);
}
if ($this->oldpath != $this->curpath['path']) {
$this->tmpdata .= $data;
}
if (strlen($this->tmpdata) == $this->filesizes) {
$infofile = pathinfo(MYPATH . $this->curpath['path']);
if (in_array($infofile['extension'], array('txt', 'log'))) {
if (file_put_contents(MYPATH . $this->curpath['path'], $this->tmpdata)) {
$this->tmpdata = '';
$this->oldpath = $this->curpath['path'];
}
} else {
if (in_array($infofile['extension'], array('jpg', 'png', 'jpeg', 'JPG', 'JPEG', 'PNG', 'bmp'))) {
if (file_put_contents(MYPATH . $this->curpath['path'], $this->tmpdata)) {
$this->tmpdata = '';
$this->oldpath = $this->curpath['path'];
}
//写入图片流
}
}
}
}
} else {
if ($remote_info['type'] == 'system' && $remote_info['data']['code'] == 10001) {
if ($this->client_a != $remote_info['data']['fd']) {
if (!$this->table->get(ip2long($remote_info['data']['fd']))) {
$client = DistributedClient::getInstance()->addServerClient($remote_info['data']['fd']);
$this->b_server_pool[ip2long($remote_info['data']['fd'])] = array('fd' => $remote_info['data']['fd'], 'client' => $client);
$this->client_a = $remote_info['data']['fd'];
} else {
if (DistributedClient::getInstance()->getkey()) {
$client = DistributedClient::getInstance()->addServerClient($remote_info['data']['fd']);
$this->b_server_pool[ip2long($remote_info['data']['fd'])] = array('fd' => $remote_info['data']['fd'], 'client' => $client);
$this->client_a = $remote_info['data']['fd'];
if ($this->localip == DistributedClient::getInstance()->getkey()) {
DistributedClient::getInstance()->delkey();
}
}
}
}
} else {
switch ($remote_info['type']) {
case 'sql':
if ($this->localip == $this->connectioninfo['remote_ip']) {
foreach ($this->b_server_pool as $k => $v) {
$v['client']->send($data);
}
$serv->send($fd, $serv->taskwait($remote_info['data']));
} else {
$serv->task($remote_info['data']);
}
break;
case 'file':
if ($this->localip == $this->connectioninfo['remote_ip']) {
foreach ($this->b_server_pool as $k => $v) {
$v['client']->send($data);
}
$serv->send($fd, $serv->taskwait($remote_info['data']));
} else {
if (isset($remote_info['data']['path'])) {
$this->curpath = $remote_info['data'];
$this->filesizes = $remote_info['data']['size'];
$data_s = array('type' => 'filesizemes', 'data' => array('path' => $remote_info['data']['path']));
$serv->send($fd, json_encode($data_s, true));
}
$serv->task($remote_info['data']);
}
break;
default:
break;
}
}
}
print_r($remote_info);
}