Skip to content

Commit

Permalink
添加hprose的支持
Browse files Browse the repository at this point in the history
添加hprose的支持
  • Loading branch information
qieangel2013 committed Nov 15, 2016
1 parent e60d5ee commit 8317ec3
Show file tree
Hide file tree
Showing 35 changed files with 5,465 additions and 7 deletions.
13 changes: 10 additions & 3 deletions application/controllers/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function indexAction() {
//第二各参数是生成日志文件名
//第三个参数$level分为:EMERG,ALERT,CRIT,ERR,WARN,NOTIC,INFO,DEBUG,SQL
logs('zas');
//$user=new HbModel('hb_users');//直接实例化给表名就行了,其他跟操作thinkphp一样
//$user=new ZysModel('hb_users');//直接实例化给表名就行了,其他跟操作thinkphp一样
//$result = $user->where($where)->select();
//echo $user->getlastsql();
//print_r($result);
Expand All @@ -86,7 +86,7 @@ public function dbtestAction() {
}
public function testAction() {
$where=array('id' =>353);
$user=new HbModel('hb_goods');
$user=new ZysModel('hb_goods');
$result = $user->where($where)->select();
print_r($result);
exit;
Expand Down Expand Up @@ -274,7 +274,7 @@ private function create_unique() {
public function swoolehttpAction(){
Yaf_Dispatcher::getInstance()->autoRender(FALSE);
$where=array('id' =>37936);
$user=new HbModel('hb_users');//直接实例化给表名就行了,其他跟操作thinkphp一样
$user=new ZysModel('hb_users');//直接实例化给表名就行了,其他跟操作thinkphp一样
$result = $user->where($where)->select();
//echo $user->getlastsql();
// echo json_encode( $result);
Expand Down Expand Up @@ -305,5 +305,12 @@ public function rpcAction(){
$sd->close();
exit;

}
public function hproseAction(){
//hprose调用
Yaf_Dispatcher::getInstance()->autoRender(FALSE);
echo hprose::getInstance()->getdata();
exit;

}
}
21 changes: 21 additions & 0 deletions application/library/hprose.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
require_once dirname(dirname(__DIR__)) . '/hprose/lib/Client.php';
class hprose
{
public static $instance;
public function __construct() {
}
public static function getdata()
{
$hprose_config = Yaf_Registry::get("config")->hprose->toArray();
$client = new Client("tcp://" . $hprose_config['ServerIp'] . ":" . $hprose_config['port'],false);
return $client->zys("zys");
}
public static function getInstance() {
if (!(self::$instance instanceof hprose)) {
self::$instance = new hprose;
}
return self::$instance;
}
}

2 changes: 1 addition & 1 deletion application/models/Hb.php → application/models/Zys.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class HbModel extends Model {
class ZysModel extends Model {
public function __construct($str='') {
parent::__construct($str);
}
Expand Down
9 changes: 6 additions & 3 deletions conf/application.ini
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ ftp.config.host="192.168.1.26"
ftp.config.username="root"
ftp.config.password="root"
;redis配置
redis.config.server="192.168.162.163"
redis.config.server="192.168.102.163"
redis.config.port="6379"
;数据库连接池配置
DbServer.async=true
DbServer.multiprocess=false
DbServer.pool_num=20
DbServer.port=9501
DbServer.logfile=MYPATH "/server/log/DbServer.log"
DbServer.localip="192.168.1.16"
DbServer.localip="192.168.102.163"
;rpc服务器配置
rpc.ServerIp="0.0.0.0"
rpc.port="9505"
Expand All @@ -79,4 +79,7 @@ distributed.logfile=MYPATH "/server/log/distributed.log"
;任务服务器配置
task.ServerIp="0.0.0.0"
task.port="9506"
task.logfile=MYPATH "/server/log/task.log"
task.logfile=MYPATH "/server/log/task.log"
;hprose服务配置
hprose.ServerIp="127.0.0.1"
hprose.port="9510"
156 changes: 156 additions & 0 deletions hprose/lib/BytesIO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<?php
/**********************************************************\
| |
| hprose |
| |
| Official WebSite: http://www.hprose.com/ |
| http://www.hprose.org/ |
| |
\**********************************************************/

/**********************************************************\
* *
* Hprose/BytesIO.php *
* *
* hprose BytesIO class for php 5.3+ *
* *
* LastModified: Jul 11, 2015 *
* Author: Ma Bingyao <[email protected]> *
* *
\**********************************************************/
class BytesIO {
protected $buffer;
protected $length;
protected $pos = 0;
protected $mark = -1;
public function __construct($string = '') {
$this->buffer = $string;
$this->length = strlen($string);
}
public function close() {
$this->buffer = '';
$this->pos = 0;
$this->mark = -1;
$this->length = 0;
}
public function length() {
return $this->length;
}
public function getc() {
if ($this->pos < $this->length) {
return $this->buffer[$this->pos++];
}
return '';
}
public function read($n) {
$s = substr($this->buffer, $this->pos, $n);
$this->skip($n);
return $s;
}
public function readfull() {
$s = substr($this->buffer, $this->pos);
$this->pos = $this->length;
return $s;
}
public function readuntil($tag) {
$pos = strpos($this->buffer, $tag, $this->pos);
if ($pos !== false) {
$s = substr($this->buffer, $this->pos, $pos - $this->pos);
$this->pos = $pos + strlen($tag);
}
else {
$s = substr($this->buffer, $this->pos);
$this->pos = $this->length;
}
return $s;
}
public function readString($n) {
$pos = $this->pos;
$buffer = $this->buffer;
for ($i = 0; $i < $n; ++$i) {
switch (ord($buffer[$pos]) >> 4) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7: {
// 0xxx xxxx
++$pos;
break;
}
case 12:
case 13: {
// 110x xxxx 10xx xxxx
$pos += 2;
break;
}
case 14: {
// 1110 xxxx 10xx xxxx 10xx xxxx
$pos += 3;
break;
}
case 15: {
// 1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx
$pos += 4;
++$i;
if ($i >= $n) {
throw new Exception('bad utf-8 encoding');
}
break;
}
default: {
throw new Exception('bad utf-8 encoding');
}
}
}
return $this->read($pos - $this->pos);
}
public function mark() {
$this->mark = $this->pos;
}
public function unmark() {
$this->mark = -1;
}
public function reset() {
if ($this->mark != -1) {
$this->pos = $this->mark;
}
}
public function skip($n) {
$this->pos += $n;
}
public function eof() {
return ($this->pos >= $this->length);
}
public function write($str, $n = -1) {
if ($n == -1) {
$this->buffer .= $str;
$n = strlen($str);
}
else {
$this->buffer .= substr($str, 0, $n);
}
$this->length += $n;
}
public function load($filename) {
$str = file_get_contents($filename);
if ($str === false) return false;
$this->buffer = $str;
$this->pos = 0;
$this->mark = -1;
$this->length = strlen($str);
return true;
}
public function save($filename) {
return file_put_contents($filename, $this->buffer);
}
public function toString() {
return $this->buffer;
}
public function __toString() {
return $this->buffer;
}
}
107 changes: 107 additions & 0 deletions hprose/lib/Client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
/**********************************************************\
| |
| hprose |
| |
| Official WebSite: http://www.hprose.com/ |
| http://www.hprose.org/ |
| |
\**********************************************************/

/**********************************************************\
* *
* Hprose/Socket/Client.php *
* *
* hprose socket client class for php 5.3+ *
* *
* LastModified: Aug 6, 2016 *
* Author: Ma Bingyao <[email protected]> *
* *
\**********************************************************/
require_once __DIR__ . '/Socket_Client.php';
require_once __DIR__ . '/HalfDuplexTransporter.php';
require_once __DIR__ . '/FullDuplexTransporter.php';
class Client extends Socket_Client {
private $hdtrans;
private $fdtrans;
public $fullDuplex = false;
public $readBuffer = 8192;
public $writeBuffer = 8192;
public $maxPoolSize = 10;
public $noDelay = true;
public $keepAlive = true;
public $options = null;
public function __construct($uris = null, $async = true) {
parent::__construct($uris, $async);
$this->hdtrans = new HalfDuplexTransporter($this, $async);
$this->fdtrans = new FullDuplexTransporter($this, $async);
}
public function __destruct() {
try {
$this->loop();
}
catch (\Exception $e) {
}
}
public function isFullDuplex() {
return $this->fullDuplex;
}
public function setFullDuplex($fullDuplex) {
$this->fullDuplex = $fullDuplex;
}
public function getReadBuffer() {
return $this->readBuffer;
}
public function setReadBuffer($size) {
$this->readBuffer = $size;
}
public function getWriteBuffer() {
return $this->writeBuffer;
}
public function setWriteBuffer($size) {
$this->writeBuffer = $size;
}
public function getMaxPoolSize() {
return $this->maxPoolSize;
}
public function setMaxPoolSize($maxPoolSize) {
if ($maxPoolSize < 1) throw new Exception("maxPoolSize must be great than 0");
$this->maxPoolSize = $maxPoolSize;
}
public function setNoDelay($value) {
$this->noDelay = $value;
}
public function isNoDelay() {
return $this->noDelay;
}
public function setKeepAlive($value) {
$this->keepAlive = $value;
}
public function isKeepAlive() {
return $this->keepAlive;
}
protected function sendAndReceive($request, stdClass $context) {
if ($this->fullDuplex) {
return $this->fdtrans->sendAndReceive($request, $context);
}
return $this->hdtrans->sendAndReceive($request, $context);
}
public function getOptions() {
return $this->options;
}
public function setOptions(array $options) {
$this->options = $options;
}
public function set($key, $value) {
$this->options[$key] = $value;
return $this;
}
public function loop() {
if ($this->fullDuplex) {
$this->fdtrans->loop();
}
else {
$this->hdtrans->loop();
}
}
}
30 changes: 30 additions & 0 deletions hprose/lib/FakeReaderRefer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**********************************************************\
| |
| hprose |
| |
| Official WebSite: http://www.hprose.com/ |
| http://www.hprose.org/ |
| |
\**********************************************************/

/**********************************************************\
* *
* Hprose/FakeReaderRefer.php *
* *
* hprose FakeReaderRefer class for php 5.3+ *
* *
* LastModified: Jul 11, 2016 *
* Author: Ma Bingyao <[email protected]> *
* *
\**********************************************************/
require_once __DIR__ . '/ReaderRefer.php';
class FakeReaderRefer implements ReaderRefer {
public function set($val) {}
public function read($index) {
throw new Exception("Unexpected serialize tag '" .
Tags::TagRef .
"' in stream");
}
public function reset() {}
}
Loading

0 comments on commit 8317ec3

Please sign in to comment.