PHP code example of cockroach / elephant
1. Go to this page and download the library: Download cockroach/elephant library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cockroach / elephant example snippets nginx
server {
listen 80;
server_name rest.elephant.com;
root /yourpath/elephant/rest/public;
index index.php;
try_files $uri $uri/ @rewrite;
location @rewrite {
rewrite ^/(.*) /index.php/$1 last;
}
location ~ \.php {
fastcgi_index /index.php;
fastcgi_pass 127.0.0.1:9000;
/usr/local/php/bin/php index.php [controllerName] [actionName] [param1] [param2] [paramN]
bash
/usr/local/php/bin/php index.php index cmd 1 2 3
/**
* @var \cockroach\client\SwooleBoot $boot
*/
$boot = Container::get('boot');
$result = $boot->call('func',[
'name' => 'func'
]);
/**
* @var \cockroach\client\Micro $micro
*/
$micro = Container::get('swoole-boot');
$result = $micro->call('v1-GetList',[
'id' => '1',
'name' => 'func get list 20 test',
'email' => '[email protected] ',
'age' => 23,
'mobile' => '13573898909',
'order' => '23492348234234'
]);
json
{
"func": {
"id": 1,
"name": "func get list 20 test",
"email": "[email protected] ",
"age": 23,
"mobile": 13573898909,
"order": 23492348234234,
"requestId": "elephant_5d9c59077f7db_eed1d",
"clientIp": "172.17.0.1",
"nickname": null,
"ip": null,
"sex": null,
"logo": null,
"imgUrl": null,
"call": null,
"patter": null
}
}