Basic implementation process of RPC based on Hprose for PHP 1.5.6 and Yii2.0.7
1. Composer has been installed, update composer to the latest version, execute the command, the result is as shown in Figure 1:
composer self-update
Error: warning: modulembstringAlready loaded in unknown on line 0
2. In php.ini, it is found that extension=php_mbstring.dll is loaded twice, and the 1007 line is commented out, as shown in Figure 2 and 3:
;extension=php_mbstring.dll
3. Run the command again, the result is no longer an error warning, but inhttps://getcomposer.org/version的文件无法下载,如图4:
composer self-update

Run the command again, the result is no longer an error warning, but inhttps://getcomposer.org/version的文件无法下载
4. Solution, enable Packagist/Composer China full image, website:http://pkg.phpcomposer.com/, execute the command, as shown in Figure 5:
composer config -g repo.packagist composerhttps://packagist.phpcomposer.com
Error:
Warning: this development build of composer is over 60 days old. It is recommended to update it by running “C:\ProgramData\ComposeSetup\bin\Composer.Phar self-update” to get the latest version.
Its meaning is:
WARNING: The development version of this composer is more than 60 days. It is recommended to update its “C:\ProgramData\ComposeSetup\bin\Composer.Phar self-update” to get the latest version.
5. Execute again: composer self-update, the result is still the request URL:https://getcomposer.org/version, as shown in Figure 6:

Execute again: composer self-update, the result is still the request url:https://getcomposer.org/version
6. Open C:\Users\Administrator\AppData\Roaming\Composer\config.json, clear the content of the file, and execute the command again:
composer config -g repo.packagist composerhttps://packagist.phpcomposer.com
The content of the config.json file is shown in Figure 7
{
“repositories”: {
“packagist”: {
“type”: “composer”,
“url”: “https://packagist.phpcomposer.com”
}
}
}

Open C:\Users\Administrator\AppData\Roaming\Composer\config.json, clear the content of the file, and execute the command again
7. Execute again: composer self-update, the update is successful, as shown in Figure 8, Figure 9:
Updating to version a8e9df55dc62d8806360be2f79ad112b8678d397.
downloading: 100%
Use composer self-update –rollback to return to version A066171DCC023AD6429881A7692E46F10E080F99
8. Install the Composer Asset plugin for Composer, execute the command, and the running result is shown in Figure 10:
composer global require “fxp/composer-asset-plugin:~1.0.0”
9. Execute the command, and the running result is shown in Figure 11:
composer global update
10. Install yii2, execute the command, and the running result is shown in Figure 12 and 13:
composer create-project yiisoft/yii2-app-advanced service.ygt.cm

Install yii2 and execute the command: composer create-project yiisoft/yii2-app-advanced service.ygt.cm

Install yii2 and execute the command: composer create-project yiisoft/yii2-app-advanced service.ygt.cm
11. Check the service.ygt.cm directory and find that the installation has been successful, as shown in Figure 14:
12. Configure the virtual host: frontend.service.ygt.cm, backend.service.ygt.cm, open frontend.service.ygt.cm, report an error, as shown in Figure 15

Configure the virtual host: frontend.service.ygt.cm, backend.service.ygt.cm, open frontend.service.ygt.cm, an error is reported
13. The reason is that the directory E:\wwwroot\service.ygt.cm\frontend\web does not exist index.php file, as shown in Figure 16

The reason is that the directory E:\wwwroot\service.ygt.cm\frontend\web does not exist index.php file
14. Update the Composer Asset plugin for Composer, execute the command, and the running result is shown in Figure 17:
composer global require “fxp/composer-asset-plugin:~1.1.1”
15. Upgrade YII2, run the command, and report an error, as shown in Figure 18:
composer update yiisoft/yii2 yiisoft/yii2-composer bower-asset/jquery.inputMask
Error: composer could not find a composer.json file in e:\wwwroot
To initialize a project, please create a composer.json file as described in thehttps://getcomposer.org/”Getting Started” section
16. Enter the directory E:\wwwroot\service.ygt.cm, and execute the command again, as shown in Figure 19:
composer update yiisoft/yii2 yiisoft/yii2-composer bower-asset/jquery.inputMask
Result:
Loading composer repositories with package information
Updating Dependencies (Including require-dev)
Nothing to install or update
GENERATING AUTOLOAD FILES
17. Initialize the application and execute the command, as shown in Figure 20:
init
0
yes
18. Open Frontend.service.ygt.cm, as shown in Figure 21
19. Open backend.service.ygt.cm, as shown in Figure 22
20. Add the application member.service.ygt.cm, copy the directory frontend as the directory member, as shown in Figure 23
21. Edit file E:\wwwroot\service.ygt.cm\environments\index.php, as shown in Figure 24
Copy frontend as member
22. Copy the frontend of dev and prod under e:\wwwroot\service.ygt.cm\environments to member, as shown in Figure 25
23. Execute the command to send, as shown in Figure 26:
init
0
yes
all
24. Search for Frontend in the member directory and replace it with member. It is recommended that the frontend in the index-test.php file is not replaced, as shown in Figure 27

Search for Frontend in the member directory, replace it with member, it is recommended that frontend in the index-test.php file is not replaced
25. Edit E:\wwwroot\service.ygt.cm\common\config\bootstrap.php, as shown in Figure 28
yii::setalias(@member, dirname(dirname(__dir__)) ./member);
26. Open member.service.ygt.cm, as shown in Figure 29, 30
27. Install hprose for php and execute the command, as shown in Figure 31 and 32:
composer require “hprose/hprose:dev-master”
28. Publish the remote service and create a new e:\wwwroot\service.ygt.cm\member\controllers\hprosecontroller.php, as shown in Figure 33:
<?php
namespace member\controllers;
use yii\base\controller;
use hprose\yii\server;
/**
* HProse Controller
*/
Class HProseController Extends Controller
{
public function beforeAction($Action)
{
Parent::BeforeAction($Action);
$server = new server();
$server->setErrorTypes(e_all);
$server->setDebugenabled(true);
$server->addMethod($action->actionmethod, $this, $action->id);
$server->start();
}
}
Or (this is recommended):
namespace member\controllers;
use yii\web\controller;
use hprose\yii\server;
/**
* HProse Controller
*/
Class HProseController Extends Controller
{
public $enablecsrfvalidation = false;
public function beforeAction($Action)
{
Parent::BeforeAction($Action);
$server = new server();
$server->setErrorTypes(e_all);
$server->setDebugenabled(true);
$server->addMethod($action->actionmethod, $this, $action->id);
$server->start();
}
}

Publish the remote service, create a new e:\wwwroot\service.ygt.cm\member\controllers\hprosecontroller.php
29. The server implementation, create a new e:\wwwroot\service.ygt.cm\member\controllers\avatarController.php, as shown in Figure 34:
<?php
namespace member\controllers;
/**
*Avatar Controller
*/
Class AvatarController extends HProseController
{
public function actionserver()
{
return 10;
}
public function actionHello() {
return “Hello !”;
}
public function actionsum() {
return strval(array_sum(func_get_args()));
}
}

Server implementation, create a new E:\wwwroot\service.ygt.cm\member\controllers\avatarController.php
30. Open the URL:http://member.service.ygt.cm/?r=avatar/server, as shown in Figure 35:
The HproSecontroller class of TP3.2.3 is to publish all the methods of the controller, and the existing implementation is to only publish the current operation method
Fa1{S6″Server”}z

The HproSecontroller class of TP3.2.3 is to publish all the methods of the controller, and the existing implementation is to only publish the current operation method
30. The client implementation, create a new e:\wwwroot\service.ygt.cm\zhidao\controllers\sitecontroller.php, as shown in Figure 36:
<?php
namespace zhidao\controllers;
use yii\web\controller;
use hprose\http\client;
/**
* site controller
*/
Class SiteController Extends Controller
{
public function actionClient() {
$client = new client(http://member.service.ygt.cm/?r=avatar/server);
echo $client->server();
}
}
31. Open the URL:http://zhidao.service.ygt.cm/?r=site/client, as shown in Figure 37:
32. Or implement the hello operation method, as shown in Figure 38 and 39:
Compared with the implementation of TP3.2.3, the disadvantage is that even the operation method under the same controller remotely needs to instantiate the client twice, but it does not feel a big problem. Generally speaking, one operation method is enough.



























