Giter Site home page Giter Site logo

hprose / hprose-php Goto Github PK

View Code? Open in Web Editor NEW
2.0K 150.0 390.0 1.13 MB

Hprose is a cross-language RPC. This project is Hprose 3.0 for PHP

License: MIT License

PHP 100.00%
rpc rpc-library rpc-framework rpc-server rpc-service rpc-client cross-platform cross-language cross-domain cross-device

hprose-php's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hprose-php's Issues

在yaf中 使用hprose 当 return 字符串时 会产生警告

我注意到是由于 Hprose\Future 中 100行~101行
if (($value !== NULL) and is_object($value) or is_string($value)) {
if (method_exists($value, 'then')) {
导致的
这是一个很棒的设计 但我觉得yaf 中的自动载入也是合理的
能否把 or is_string($value) 去掉

405: Method Not Allowed

PHP Fatal error: Uncaught Exception: 405: Method Not Allowed

使用如下代码时,会报错,服务端使用nginx加了一个重定向wus/v1/ => public/index.php?version=v1

$client = Client::create('http://xxxx/wus/v1/', false);
$client->xxx();

不知道怎么处理?

关于TCPSERVER 的疑问

最近项目使用hprse tcp server 后,server 进程不怎么稳定,总是每个两三天客户端就调用不了服务端的方法,登陆到服务器查看server 进程没什么异常,进程依然处于正常监听状态。奇怪的事,杀死server 进程,再重启进程,一切又正常了,这个问题困绕了我很久了,会不会是因为程序中使用exit die之类?或者是其他的问题?请赐教,非常感谢!

请教一下性能的问题

最近用hprose做服务,测试程序中以前的业务逻辑不变,只是多加了hprose;

//上面是老逻辑代码
$hprose = new Client("tcp://0.0.0.0:1314", false);
$hprose->test();

test()方法有涉及到逻辑处理有一定性能开销的,我想知道这个new [Client()的性能开销大不大的?压测了下感觉原来的代码性能降了很多;
没加hprose:
image

加了hprose:
image

还有问下有什么技术手段,可以让这个new的Client不用频繁的实例化?1000个用户的http请求就是new1000次了,会产生1000个tcp连接,这种并发高了咋办?

关于客户端返回字符串问题

PHP框架 Yaf
服务器端:

<?php
class IndexController extends Rpc {

   /**
     * UserController::init()
     *
     * @return void
     */
    public function init() {
        parent::init();
        Yaf_Dispatcher::getInstance()->disableView();
    }
    public function indexAction(){}

    public function abcFunc($num) {//默认Action
        return 'Hello,'.$num;
    }

    public function adFunc($a){
      $a = '**';
      $c = 'Hello';
      $b = array('asf','Hello','asdf','**');

      return $b;
    }
}

客户端:

<?php
use Hprose\Client;

class IndexController extends Yaf_Controller_Abstract {
    protected $web = '';
    public function init(){
        $config = Yaf_Application::app()->getConfig();
        Yaf_Registry::set("config", $config);

        $rpc = $config->get("rpc");
        Yaf_Registry::set("rpc", $rpc);

        $this->web = Client::create($rpc->host . 'index', false);
    }

   public function indexAction() {//默认Action

        $a = $this->web->abcFunc(1);
        var_dump($a);
        exit;
        //$a = "Hello World";
        $this->getView()->assign("content", $a);
   }

   public function aaAction(){
     $a = $this->web->aaFunc();
     var_dump($a);
     exit;
   }
}
?>

问题:

服务端 修改 返回的变量 当为 $a 的时候,报错如下:

Yaf_Loader::autoload(): Failed opening script E:\xampp\htdocs\blog/application/\library\**.php: No such file or directory

当为$c时,报错如下:

Yaf_Loader::autoload(): Failed opening script E:\xampp\htdocs\blog/application/\library\Hello.php: No such file or directory

联系QQ:
[email protected]

hprose 处理 emoji 报 iconv异常

异常栈如下

Exception: iconv(): Detected an illegal character in input string in /home/work/app/vendor/hprose/hprose/src/Hprose/Client.php:368
Stack trace:
#0 /home/work/app/vendor/hprose/hprose/src/Hprose/Client.php(470): Hprose\Client->decode('Es54"iconv(): D...', Array, Object(stdClass))
#1 /home/work/app/vendor/hprose/hprose/src/Hprose/Client.php(482): Hprose\Client->syncInvokeHandler('updateUserInfo', Array, Object(stdClass))
#2 /home/work/app/vendor/hprose/hprose/src/Hprose/HandlerManager.php(40): Hprose\Client->invokeHandler('updateUserInfo', Array, Object(stdClass))
#3 /home/work/app/vendor/hprose/hprose/src/Hprose/Client.php(598): Hprose\HandlerManager->Hprose\{closure}('updateUserInfo', Array, Object(stdClass))
#4 /home/work/app/vendor/hprose/hprose/src/Hprose/Client.php(423): Hprose\Client->invoke('updateUserInfo', Array)
#5 /home/work/app/api/modules/user/controllers/InfoController.php(205): Hprose\Client->__call('updateUserInfo', Array)
#6 [internal function]: api\modules\user\controllers\InfoController->actionUpdate()
#7 /home/work/app/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#8 /home/work/app/vendor/yiisoft/yii2/base/Controller.php(156): yii\base\InlineAction->runWithParams(Array)
#9 /home/work/app/vendor/yiisoft/yii2/base/Module.php(523): yii\base\Controller->runAction('update', Array)
#10 /home/work/app/vendor/yiisoft/yii2/web/Application.php(102): yii\base\Module->runAction('user/info/updat...', Array)
#11 /home/work/app/vendor/yiisoft/yii2/base/Application.php(380): yii\web\Application->handleRequest(Object(yii\web\Request))
#12 /home/work/app/api/web/index.php(16): yii\base\Application->run()
#13 {main}

关于文档章节 - Hprose 客户端 的疑问

“Hprose 客户端” 一节提到了 onError 事件和 onFailswitch 事件,但是并没有讲如何注册该事件。
另外,关于“onError 事件”有这样一句描述:“当客户端采用回调方式进行调用时,并且回调函数没有参数,如果发生异常,该事件会被调用”,什么叫“回调函数没有参数”,没有设置参数?没有传回参数?,这里的参数指的是 callback 函数的 $args 形参还是整个 callback 函数的参数?

使用代理之后,php的hprose无法使用,报错如下...是什么原因呢?

Fatal error: Uncaught Exception: Wrong Response:
HTTP/1.1 200 OK
Server: nginx/1.10.0
Date: Thu, 16 Nov 2017 00:44:51 GMT
Content-Type: text/plain;charset=UTF-8
Content-Length: 2172
Connection: keep-alive
X-Powered-By: PHP/7.1.9
Set-Cookie: PHPSESSID=dbcu4en8r14a2251gldpfivo49; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache

Rm2{s4"code"s3"200"s4"data"m9{s5"total"i122;s8"per_page"i10;s12"current_page"1s9"last_page"i13;s13"next_page_url"s8"/?page=2"s13"prev_page_url"ns4"from"1s2"to"i10;r3;a10{m13{s2"id"i176;s2"ip"s15"180.173.234.115"s4"uuid"s12"zhangziliang"s6"shared"s3"yes"s6"showed"1s4"href"s28"https://sspai.com/post/33299"s4"time"ns11"description"s44"通过终端命令改变 Launchpad 中应用图标的大小丨一日一技 · Mac - 少数派"s8"extended"es3"tag"es4"hash"ns4"meta"ns11"update_time"i1510706688;}m13{r16;i175;r17;r18;r19;r20;r21;r22;r23;1r24;s18"https://wxvip.org/"r26;nr27;s9"wxvip.org"r29;er30;s9"wechat wx"r31;nr32;nr33;i15106 in /Users/ziziliang/Google 云端硬盘/alfred/Alfred.alfredpreferences/workflows/user.workflow.BB9BF069-D107-4B0F-9034-2FAFA2F39327/vendor/hprose/hprose/src/Hprose/Client.php on line 374

客户端用完要不要关闭?

use Hprose\Client;
$client = Client::create('http://127.0.0.1:9999/', false);
var_dump($client->hello("world"));
$inputFileName='/nfs_file/sites/sys'.'/m/pingan/excel/8m.xlsx';//$_SERVER['DOCUMENT_ROOT']解析一个8M的excel
print_r($client->readExcel($inputFileName,0,68964,5));
echo "sss";die;

请教一个promise异步的问题

在学习hprose的过程中,遇到了一个惊到一众phper的效果
php version 5.6.20
image
结果的话大大应该也清楚了
image

真异步了!学艺不精,研习了一天源码也没有搞懂这个异步到底是怎么实现的。只有前来请教了。

服务端对对象添加别名问题

...
$server = new HproseSwooleServer("tcp://127.0.0.1:1504");
$server->setErrorTypes(E_ALL);
$server->setDebugEnabled();

$server->add(new TestModel(),'test');
...
[server]# php hprose_swoole_tcp.php 
PHP Warning:  array_diff(): Argument #1 is not an array in 
hprose-php/Hprose/Service.php on line 330
PHP Warning:  Invalid argument supplied for foreach() in 
hprose-php/Hprose/Service.php on line 432
PHP Warning:  Invalid argument supplied for foreach() in 
hprose-php/Hprose/Service.php on line 442

对象添加了别名会又问题,
客户端调用找不到方法 Can't find this function TestModel_one().

[Test] phpunit 6 compatibility

PHPUnit_Framework_TestCase no longer works with PhpUnit 6.0+

PHP Fatal error:  Class 'PHPUnit_Framework_TestCase' not found

Class name with "_" get stdClass obj after unserialize

classA.php
<?php

namespace name_A{
    class Test_1 {

        public $string = 'thisIsAString';
        public $double = 12.0123838434893;
        public $int = 1;
    }
}

test code1:
$objTest1 = new name_A\Test_1();

$data = \Hprose\Formatter::serialize($objTest1);
echo $data,"\n";
//c13"name_A_Test_1"3{s6"string"s6"double"s3"int"}o0{s13"thisIsAString"d12.012383843489;1}

test code2:
$data = 'c13"name_A_Test_1"3{s6"string"s6"double"s3"int"}o0{s13"thisIsAString"d12.012383843489;1}';
var_dump(\Hprose\Formatter::unserialize($data));
/*
output:
class stdClass#5 (3) {
  public $string =>
  string(13) "thisIsAString"
  public $double =>
  double(12.012383843489)
  public $int =>
  int(1)
}
*/

namespace tag "" was replace by "" what cause true class lost.
i think use "\t" or "\n" to instead of "
" in full class name, and it would be better ?
and there is any way to resolve it ?

and & i found java did this too.
in ClassUtils.java

public final static String getClassAlias(Class<?> type) {
        String className = HproseClassManager.getClassAlias(type);
        if (className == null) {
            className = type.getName().replace('.', '_').replace('$', '_');
            HproseClassManager.register(type, className);
        }
        return className;
    }

A syntax error in the code

A syntax error in the code

  • Hprose\Future\functions.php Line 161
 158                   function($reason) use ($index, &$reasons, &$n, $reject) {
 159                      $reasons[$index] = $reason;
 160                      if (--$n === 0) {
 161                            $reject();
 162                       }
 163                  }

用了httpserver和httpclient做测试,然后报错了

代码都是直接从readme里面取的,稍微调整了一下,server正常,client报错了

server

<?php
require_once('hprosesrc\Hprose.php');

function hello($name) {
    return 'Hello ' . $name;
}

$server = new HproseHttpServer();
$server->addFunction('hello');
$server->start();

client

<?php
require_once('hprosesrc\Hprose.php');
$client = new HproseHttpClient('http://127.0.0.1/helloserver.php');
echo $client->hello('World');

错误提示

Object of class Hprose\Future could not be converted to string

环境是windows php5.4.16

用Tcp方式连接通讯,执行服务端报错,怎么解决的呢

socket_import_stream() expects parameter 1 to be resource, boolean given in
这是什么问题呢? #

class Hello
{
public function say($name)
{
return 'Hello '.$name;
}
}

use Hprose\Socket\Server;

$server = new Server("tcp://127.0.0.1:8000");

$server->add((new Hello()));

$server->debug = true;

$server->start();

$context->userdata无法收到数据

想在客户端调用服务端的时候统一加上token
$settings = new InvokeSettings(array('userdata' => ['token' => $userData['token']]));
$client->hello($settings);
在服务端无法收到userdata
$this->server->addInvokeHandler(function ($name, array &$args, \stdClass $context, \Closure $next) {
//$context中没有userdata
})

测试通讯失败

require_once "vendor/autoload.php";
use Hprose\Http\Server;
function hello($name) {
return "Hello " . $name;
}
$server = new Server();
$server->addFunction("hello");
$server->start();

require_once "vendor/autoload.php";
use Hprose\Http\Client;
use Hprose\InvokeSettings;
use Hprose\ResultMode;
$client = new Client('http://order.local/s.php', false);
echo $client->hello("docker", new InvokeSettings(array('mode' => ResultMode::Normal)));

不通,可能是哪错了?服务器地址正式环境可用

Laravel 自关联的数据,在客户端无法解析

如果一个方法,返回值是 一个数据对象 ModelA $a,它的一个属性 还是这个类 ModelA 构成的数据对象 $b, 那么这个返回结果在客户端就无法解析,报错为
Unexpected serialize tag '{' in stream

实例代码如下:

Server:

public function testConnection()
    {
        $label = Label::find(1);
        $label->child = Label::find(2);
        return $label;
    }

请问应当如何解决。

服务端调用出错Argument func must be callable.

在laravel中服务端调用出错提示:
Argument func must be callable.

`namespace App\Http\Controllers;
use Hprose\Http\Server;
use Illuminate\Http\Request;

class TestController extends Controller
{
public function index(){
$server = new Server();
$server->addFunction('hello',$this);
$server->start();
}
public function hello(){
return "Hello";
}
}`

关于hprose server报出http状态码500的错误

php 的 hprose server,

我在关闭报错误(display_error:Off)之后会报一个http code=500的内部错误,但是我打开报错误就是正常的,而且我这边看日志确实没有啥错误。

前几天也出现了,我把代码全部删除,重新clone一份又正常了,搞不太懂,是不是hprose内部会缓存代码呢?之前我修改了一些server的代码,客户端去调用都会缓存一会儿,每次都重启了php都没有用。

hprose/hprose/src/Hprose/Http/Client.php(279): Hprose\Http\Client->getContents('HTTP/1.1 500 In...', Object(stdClass))
hprose/hprose/src/Hprose/Http/Client.php(296): Hprose\Http\Client->syncSendAndReceive('Cs4"post"a1{m3{...', Object(stdClass))
hprose/hprose/src/Hprose/Client.php(49 in /home/wwwroot/demo.gateapi.cn/vendor/hprose/hprose/src/Hprose/Http/Client.php on line 266

支持php7吗

Fatal error: Uncaught Error: Class 'swoole_http_server' not found in /Library/WebServer/Documents/hprose-php/src/Hprose/Swoole/Http/Server.php:27 Stack trace: #0 /Library/WebServer/Documents/hprose-php/src/Hprose/Swoole/Server.php(58): Hprose\Swoole\Http\Server->__construct('127.0.0.1', 10000, 'SWOOLE_PROCESS') #1 /Library/WebServer/Documents/hprose-php/src/Hprose/Swoole/Server.php(90): Hprose\Swoole\Server->init_server('http://127.0.0....') #2 /Library/WebServer/Documents/hprose-php/demo/server.php(13): Hprose\Swoole\Server->__construct('http://127.0.0....') #3 {main} thrown in /Library/WebServer/Documents/hprose-php/src/Hprose/Swoole/Http/Server.php on line 27

无法更新版本

Installs: hprose/hprose-php:dev-master b05f780
composer 安装只能更新到这个提交,更新不到2.0.30。是什么原因?

序列化长度计算是不是不准?

strlen(iconv('UTF-8', 'UTF-16LE', $s)) >> 1;

上面这个算长度的,某些情况下会为0。命令行执行为0,浏览器执行为正确的值。

导致请求的时候失败。

异常处理

请问下使用的时候,客户端参数传输错误导致服务端异常退出,try cactch 无法捕获异常,onSendError也处理不了,请问下有什么解决方案吗

require __DIR__.'/../vendor/autoload.php';
use Hprose\Swoole\Server;
function a($b, $c) {
    echo $b;
    echo  $c;
}

    $server = new Server("tcp://0.0.0.0:1314");
    $server->setDebugEnabled(true);
    dump($server->isDebugEnabled());
    $server->addFunction('a');
    $server->onSendError = function ($error, \stdClass $context) {
        dump($error->getMessage());
        return true;
    };
    $server->start();


    $client = \Hprose\Client::create('tcp://127.0.0.1:1314', false);
    return $client->a(['name' => 'xz'],  new InvokeSettings(array('mode' => ResultMode::Normal)));

可否将swoole的on函数接口放出

现在的HproseSwoole等Server都不能直接设置各种回调函数,比如onStart,onWorkerStart,onTask等,这样限制了不少功能,能否在下一版本的Hprose中放出来,或者我这边做好提一个PR?

死循环的问题

src/Hprose/Socket/Transporter.php

private function write($stream, $request) {
        $buffer = $this->appendHeader($request);
        $length = strlen($buffer);
        while (true) {
            $sent = @fwrite($stream, $buffer, $length);
            if ($sent === false) {
                return false;
            }
            if ($sent < $length) {
                $buffer = substr($buffer, $sent);
                $length -= $sent;
            }
            else {
                return true;
            }
        }
    }

fwrite 写数据时加了@

如果用 set_error_handler() 设定了自定义的错误处理函数,仍然会被调用,但是此错误处理函数可以(并且也应该)调用 error_reporting(),而该函数在出错语句前有 @ 时将返回 0。 --php手册

如果fwrite出现异常,将会出现死循环

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.