Directly convert all hprose for PHP files (hprosecommon. PHP, hproseio. PHP, hprosehttpserver. PHP and hprosehttpclient. directly copy to the directory of your development environment without any installation steps.
CreateHproseOfHelloServer
It is very easy to create a PHP hprose server. Next we will take the Linux environment as an example to explain. Assume that the Web server (Apache, Lighttpd, or any other HTTP server) has been configured in Linux, and PHP can be executed.ProgramAnd the publishing path is/var/www. Then we create an hprose directory under the release directory and put several hprose for PHP files in this directory. Create a helloserver. php file in the release directory. The content is as follows:
PHPCode
<? PHP
Include("Hprose/hprosehttpserver. php ");
FunctionHello ($ name ){
Return"Hello". $ name;
}
$ Server =NewHprosehttpserver ();
$ Server-> addfunction ("hello ");
$ Server-> handle ();
?>
In this way, our server has been created. Is it quite simple?
Let's take a look at the effect. Open the browser and enter the following url: http: // localhost/helloserver. php. Then press Enter. If the following page is displayed, our service is successfully released.
Next, let's take a look at how to create a client.
CreateHproseOfHelloClient
It is easier to create the PHP hprose client. The helloclient. php file is also created in the release directory. The content is as follows:
PHPCode
<? PHP
Include("Hprose/hprosehttpclient. php ");
$ Client =NewHprosehttpclient ("http: // localhost/helloserver. php ");
Echo $ client-> Hello ("hprose ");
?>
Enter http: // localhost/helloclient. php In the browser, or enter PHP helloclient. php In the command line. If the following result is displayed:
Reference
Hello hprose
It indicates that the client has been created successfully!