没有不值得去解决的问题,也没有不值得去学习的技术!

Resolving Compatibility Issues After Upgrading Yii2.0.9 and Hprose for PHP 2.0 via Composer

"require": {         "hprose/hprose-yii": "dev-master"     }

1. For the basic implementation of RPC based on Hprose for PHP 1.5.6 and Yii 2.0.7, please refer to the URL: https://www.shuijingwanwq.com/2016/03/24/953/

2. To upgrade Yii2 via Composer, execute the command: composer update, as shown in Figure 1:

Upgrading Yii2 via Composer, executing the command: composer update
Figure 1

3. Opening the URL: http://trade.service.ygt.cm/area/get-area-mobile , an error is reported, as shown in Figure 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

PHP Warning – yii\base\ErrorException
Figure 2

4. After analyzing the cause, I found that after the upgrade, when committing to SVN, E:\wwwroot\service.ygt.cm\vendor\hprose\hprose\src\Hprose\Yii was already missing, as shown in Figure 3:

After analyzing the cause, I found that after the upgrade, when committing to SVN, E:\wwwroot\service.ygt.cm\vendor\hprose\hprose\src\Hprose\Yii was already missing
Figure 3

5. A screenshot of the source code in E:\wwwroot\service.ygt.cm\trade\controllers\HproseController.php shows that the referenced class file no longer exists, which naturally causes an error, as shown in Figure 4:

The referenced class file no longer exists, which naturally causes an error
Figure 4

6. Opening the URL: https://github.com/hprose/hprose-php/wiki/%E5%AE%89%E8%A3%85 , I edited E:\wwwroot\service.ygt.cm\composer.json, as shown in Figure 5:

“require”: {
“hprose/hprose-yii”: “dev-master”
}

    "require": {         "hprose/hprose-yii": "dev-master"     }
Figure 5

7. In Windows PowerShell, execute the command: composer update, as shown in Figure 6:
It installed yiisoft/yii, which can be ignored for now; it is recommended to remove it.

It installed yiisoft/yii, which can be ignored for now; it is recommended to remove it
Figure 6

8. Opening the URL: http://trade.service.ygt.cm/area/get-area-mobile , an error is reported, as shown in Figure 7:
Unknown Property – yii\base\UnknownPropertyException
Getting unknown property: yii\web\Request::session

Unknown Property – yii\base\UnknownPropertyException Getting unknown property: yii\web\Request::session
Figure 7

9. Edit E:\wwwroot\service.ygt.cm\vendor\hprose\hprose-yii\src\Hprose\Yii\Service.php, as shown in Figure 8:

// $context->session = $request->session;
$context->session = \Yii::$app->session;

// $context->session = $request->session; $context->session = \Yii::$app->session;
Figure 8

10. Open the URL: http://trade.service.ygt.cm/area/get-area-mobile , as shown in Figure 9:

Opening the server side works as expected
Figure 9

11. The client invocation throws an error, as shown in Figure 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 ( ) )

Client invocation throws an error: Hprose\Future Object ( [state] => 1 [value] => Hprose\Future Object ( [state] => 0 [value] => [reason] => [subscribers:Hprose\Future:private] => Array ( ) ) [reason] => [subscribers:Hprose\Future:private] => Array ( ) )
Figure 10

12. Based on the prompt in Figure 6, install the pecl extension for Hprose for PHP. Installing it can effectively improve Hprose’s performance. Open the URL: https://github.com/hprose/hprose-php/wiki/hprose-%E7%9A%84-pecl-%E6%89%A9%E5%B1%95 , as shown in Figure 11:

Install the pecl extension for Hprose for PHP; installing it can effectively improve Hprose's performance
Figure 11

13. After analysis, in version 2.0, client invocations are asynchronous by default. If a synchronous invocation is needed, set $async = false, as shown in Figure 12:

After analysis, in version 2.0, client invocations are asynchronous by default. If a synchronous invocation is needed, set $async = false
Figure 12

14. Run the client invocation, which works as expected, as shown in Figure 13:

Run the client invocation, which works as expected
Figure 13

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系