2015-08-23 02:17:54 +03:00
|
|
|
# Vitess PHP
|
|
|
|
|
|
|
|
This folder contains the PHP client for Vitess.
|
|
|
|
|
2015-12-09 01:10:38 +03:00
|
|
|
For a simple example of using the API, see the [client.php]
|
|
|
|
(https://github.com/youtube/vitess/blob/master/examples/local/client.php)
|
|
|
|
script, which works with the environment created by the [local setup example]
|
|
|
|
(http://vitess.io/getting-started/local-instance.html).
|
|
|
|
|
|
|
|
There is also a similar example client for the [VTGateV3 demo]
|
|
|
|
(https://github.com/youtube/vitess/tree/master/examples/demo) environment.
|
2015-08-23 02:17:54 +03:00
|
|
|
|
|
|
|
## Prerequisites
|
|
|
|
|
2015-10-16 10:07:02 +03:00
|
|
|
PHP 5.5+ is required.
|
2015-08-23 02:17:54 +03:00
|
|
|
|
2015-10-16 10:07:02 +03:00
|
|
|
### gRPC Extension Module
|
|
|
|
|
|
|
|
Install the [gRPC extension module](https://pecl.php.net/package/gRPC).
|
|
|
|
|
|
|
|
For example, on Debian/Ubuntu:
|
2015-08-23 02:17:54 +03:00
|
|
|
|
|
|
|
``` sh
|
|
|
|
$ sudo apt-get install php5-dev php5-cli php-pear
|
2015-10-16 10:07:02 +03:00
|
|
|
$ sudo pecl install grpc-beta
|
|
|
|
```
|
|
|
|
|
|
|
|
### gRPC Dependencies
|
|
|
|
|
|
|
|
To download the dependencies of the gRPC PHP library, run Composer:
|
|
|
|
|
|
|
|
``` sh
|
2016-01-14 00:36:35 +03:00
|
|
|
$ cd vitess
|
|
|
|
vitess$ curl -sS https://getcomposer.org/installer | php
|
|
|
|
vitess$ php composer.phar install
|
2015-08-23 02:17:54 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
## Unit Tests
|
|
|
|
|
|
|
|
To run the tests, first install PHPUnit:
|
|
|
|
|
|
|
|
``` sh
|
2015-10-02 21:21:53 +03:00
|
|
|
$ wget https://phar.phpunit.de/phpunit-4.8.9.phar
|
|
|
|
$ mv phpunit-4.8.9.phar $VTROOT/bin/phpunit
|
2015-08-25 00:15:47 +03:00
|
|
|
$ chmod +x $VTROOT/bin/phpunit
|
2015-08-23 02:17:54 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
Then run the tests like this:
|
|
|
|
|
|
|
|
``` sh
|
2015-10-16 20:54:19 +03:00
|
|
|
vitess$ . dev.env
|
|
|
|
vitess$ make php_test
|
2015-08-23 02:17:54 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
### Coverage
|
|
|
|
|
|
|
|
In addition to PHPUnit, you also need to install xdebug, if you want to see
|
|
|
|
coverage:
|
|
|
|
|
|
|
|
``` sh
|
|
|
|
$ sudo pecl install xdebug
|
|
|
|
[...]
|
|
|
|
Build process completed successfully
|
|
|
|
Installing '/usr/lib/php5/20121212/xdebug.so'
|
|
|
|
|
|
|
|
# Where should we put the ini file?
|
|
|
|
$ php --ini
|
|
|
|
Configuration File (php.ini) Path: /etc/php5/cli
|
|
|
|
Loaded Configuration File: /etc/php5/cli/php.ini
|
|
|
|
Scan for additional .ini files in: /etc/php5/cli/conf.d
|
|
|
|
|
|
|
|
# Make an ini file for xdebug.
|
2015-08-23 03:49:09 +03:00
|
|
|
$ sudo sh -c "echo \"zend_extension=$(pecl config-get ext_dir default)/xdebug.so\" > /etc/php5/cli/conf.d/20-xdebug.ini"
|
2015-08-23 02:17:54 +03:00
|
|
|
|
|
|
|
# Check that xdebug is being loaded.
|
|
|
|
$ php -m | grep xdebug
|
|
|
|
xdebug
|
|
|
|
```
|
|
|
|
|
|
|
|
Then you can run a coverage check with PHPUnit:
|
|
|
|
|
|
|
|
``` sh
|
2016-01-14 00:36:35 +03:00
|
|
|
vitess$ phpunit --coverage-html php/_test
|
2015-08-23 02:17:54 +03:00
|
|
|
|
|
|
|
# Open in browser.
|
2016-01-14 00:36:35 +03:00
|
|
|
vitess$ xdg-open php/_test/index.html
|
2015-08-23 02:17:54 +03:00
|
|
|
```
|
|
|
|
|