#Overview
This directory contains source code for PHP implementation of gRPC layered on shared C library.
#Status
Beta
Prerequisite: php >=5.5, phpize, pecl, phpunit
Linux (Debian):
$ sudo apt-get install php5 php5-dev php-pearLinux (CentOS):
$ yum install php55w
$ yum --enablerepo=remi,remi-php55 install php-devel php-pearMac OS X:
$ curl -O http://pear.php.net/go-pear.phar
$ sudo php -d detect_unicode=0 go-pear.pharPHPUnit:
$ wget https://phar.phpunit.de/phpunit-old.phar
$ chmod +x phpunit-old.phar
$ sudo mv phpunit-old.phar /usr/bin/phpunitInstall the gRPC PHP extension
sudo pecl install grpc-betaThis will compile and install the gRPC PHP extension into the standard PHP extension directory. You should be able to run the unit tests, with the PHP extension installed.
To run tests with generated stub code from .proto files, you will also need the composer, protoc and protoc-gen-php binaries. You can find out how to get these below.
Clone this repository
$ git clone https://github.com/grpc/grpc.gitBuild and install the gRPC C core library
$ cd grpc
$ git pull --recurse-submodules && git submodule update --init --recursive
$ make
$ sudo make installInstall the gRPC PHP extension from PECL
$ sudo pecl install grpc-betaOr, compile from source
$ cd grpc/src/php/ext/grpc
$ phpize
$ ./configure
$ make
$ sudo make installAdd this line to your php.ini file, e.g. /etc/php5/cli/php.ini
extension=grpc.soYou will need the source code to run tests
$ git clone https://github.com/grpc/grpc.git
$ cd grpc
$ git pull --recurse-submodules && git submodule update --init --recursiveRun unit tests
$ cd grpc/src/php
$ ./bin/run_tests.shThis section specifies the prerequisites for running the generated code tests, as well as how to run the tests themselves.
If you don't have it already, install composer to pull in some runtime dependencies based on the composer.json file.
$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer
$ cd grpc/src/php
$ composer installAgain if you don't have it already, you need to install the protobuf compiler protoc, version 3.0.0+.
If you compiled the gRPC C core library from source above, the protoc binary should have been installed as well. If it hasn't been installed, you can run the following commands to install it.
$ cd grpc/third_party/protobuf
$ sudo make install # 'make' should have been run by core grpcAlternatively, you can download protoc binaries from the protocol buffers Github repository.
You need to install protoc-gen-php to generate stub class .php files from service definition .proto files.
$ cd grpc/src/php/vendor/datto/protobuf-php # if you had run `composer install` in the previous step
OR
$ git clone https://github.com/stanley-cheung/Protobuf-PHP # clone from github repo
$ gem install rake ronn
$ rake pear:package version=1.0
$ sudo pear install Protobuf-1.0.tgzGenerate client stub classes from .proto files
$ cd grpc/src/php
$ ./bin/generate_proto_php.shRun a local server serving the math services. Please see Node for how to run an example server.
$ cd grpc
$ npm install
$ nodejs src/node/test/math/math_server.jsRun the generated code tests
$ cd grpc/src/php
$ ./bin/run_gen_code_test.shInstall apache2, in addition to php5 above
$ sudo apt-get install apache2Add this line to your php.ini file, e.g. /etc/php5/apache2/php.ini
extension=grpc.soRestart apache
$ sudo service apache2 restartMake sure the Node math server is still running, as above.
$ cd grpc
$ npm install
$ nodejs src/node/test/math/math_server.jsMake sure you have run composer install to generate the vendor/autoload.php file
$ cd grpc/src/php
$ composer installMake sure you have generated the client stub math.php
$ ./bin/generate_proto_php.shCopy the math_client.php file into your Apache document root, e.g.
$ cp tests/generated_code/math_client.php /var/www/htmlYou may have to fix the first two lines to point the includes to your installation:
include 'vendor/autoload.php';
include 'tests/generated_code/math.php';Connect to localhost/math_client.php in your browser, or run this from command line:
$ curl localhost/math_client.phpInstall nginx and php5-fpm, in addition to php5 above
$ sudo apt-get install nginx php5-fpmAdd this line to your php.ini file, e.g. /etc/php5/fpm/php.ini
extension=grpc.soUncomment the following lines in your /etc/nginx/sites-available/default file:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
Restart nginx and php-fpm
$ sudo service nginx restart
$ sudo service php5-fpm restartMake sure the Node math server is still running, as above.
$ cd grpc
$ npm install
$ nodejs src/node/test/math/math_server.jsMake sure you have run composer install to generate the vendor/autoload.php file
$ cd grpc/src/php
$ composer installMake sure you have generated the client stub math.php
$ ./bin/generate_proto_php.shCopy the math_client.php file into your Nginx document root, e.g.
$ cp tests/generated_code/math_client.php /var/www/htmlYou may have to fix the first two lines to point the includes to your installation:
include 'vendor/autoload.php';
include 'tests/generated_code/math.php';Connect to localhost/math_client.php in your browser, or run this from command line:
$ curl localhost/math_client.php