1、基于Hprose for PHP 1.5.6、Yii2.0.7的RPC的基本实现,请参考网址:http://www.shuijingwanwq.com/2016/03/24/953/
2、通过Composer升级Yii2,执行命令:composer update,如图1:
3、打开网址:http://trade.service.ygt.cm/area/get-area-mobile ,报错,如图2:
PHP Warning – yii/base/ErrorException
include(E:/wwwroot/service.ygt.cm/vendor/hprose/hprose/src/Hprose/Yii/Server.php): failed to open stream: No such file or directory
4、分析原因,发现升级之后,提交SVN时,E:/wwwroot/service.ygt.cm/vendor/hprose/hprose/src/Hprose/Yii 已经缺少了,如图3:
5、E:/wwwroot/service.ygt.cm/trade/controllers/HproseController.php 的源代码截图,引用的类文件已经不存在,自然报错了,如图4:
6、打开网址:https://github.com/hprose/hprose-php/wiki/%E5%AE%89%E8%A3%85 ,编辑E:/wwwroot/service.ygt.cm/composer.json,如图5:
“require”: {
“hprose/hprose-yii”: “dev-master”
}
7、在Windows PowerShell中执行命令:composer update,如图6:
安装了yiisoft/yii,可以暂不去管的,建议删除掉;
8、打开网址:http://trade.service.ygt.cm/area/get-area-mobile ,报错,如图7:
Unknown Property – yii/base/UnknownPropertyException
Getting unknown property: yii/web/Request::session
9、编辑E:/wwwroot/service.ygt.cm/vendor/hprose/hprose-yii/src/Hprose/Yii/Service.php,如图8:
// $context->session = $request->session;
$context->session = /Yii::$app->session;
10、打开网址:http://trade.service.ygt.cm/area/get-area-mobile ,如图9:
11、客户端调用,出错,如图10:
Hprose/Future Object ( [state] => 1 [value] => Hprose/Future Object ( [state] => 0 [value] => [reason] => [subscribers:Hprose/Future:private] => Array ( ) ) [reason] => [subscribers:Hprose/Future:private] => Array ( ) )
12、根据图6的提示,安装Hprose for PHP的pecl扩展,安装它之后可以有效的提高 Hprose 的性能。打开网址:https://github.com/hprose/hprose-php/wiki/hprose-%E7%9A%84-pecl-%E6%89%A9%E5%B1%95 ,如图11:
13、经分析,2.0版本,客户端调用,默认为异步,如果需要同步调用,则$async = false,如图12:
14、运行客户端调用,符合预期,如图13:
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/250367.html