Skip to content

Commit 6fd67d8

Browse files
committed
fix: fix codedump and replace return zval* to return zval
1 parent a6f8b20 commit 6fd67d8

30 files changed

+1506
-325
lines changed

doc/ApiDoc.md

Lines changed: 45 additions & 54 deletions
Large diffs are not rendered by default.

doc/ApiDoc_ZH.md

Lines changed: 898 additions & 0 deletions
Large diffs are not rendered by default.

doc/HowToBuild.md

Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,49 @@
11
# How to build
22

3-
## 前期准备
4-
### 构建 Polaris-CPP
3+
## Preparation
4+
### Build Polaris-CPP
55

6-
`polaris-cpp`项目`clone`到你本地的一个目录中
6+
Put the `polaris-cpp` project `clone` to a directory on your local
77

88
```shell
9-
cd {你的一个目录}
10-
# 下载
9+
cd {One of your directories}
10+
11+
# run git clone
1112
git clone [email protected]:polarismesh/polaris-cpp.git
1213

13-
# 执行编译构建
14+
# run compile build
1415

1516
make && make package
1617
```
1718

18-
执行make package后会在当前目录下生成一个polaris_cpp_sdk.tar.gz压缩文件。该文件的内容如下
19+
After executing make package, a polaris_cpp_sdk.tar.gz compressed file will be generated in the current directory. The content of the file is as follows
1920

2021
```
21-
|-- include/polaris # 头文件
22+
|-- include/polaris # head File
2223
| |-- consumer.h provider.h limit.h config.h context.h log.h defs.h ...
23-
|-- dlib # 动态库
24+
|-- dlib # Dynamic library
2425
| |-- libpolaris_api.so
25-
`-- slib # 静态库
26+
`-- slib # Static library
2627
|-- libpolaris_api.a libprotobuf.a
2728
```
2829

29-
对文件`polaris_cpp_sdk.tar.gz`进行解压,将`slib`目录下的`libpolaris_api.a`以及`libprotobuf.a`拷贝到本项目(`polaris-php`)的`lib`目录下
30-
31-
```shell
32-
cd {你的一个目录}/polaris-cpp
33-
```
34-
35-
最终的目录结构如下
30+
Unzip the file `polaris_cpp_sdk.tar.gz`, copy `libpolaris_api.a` and `libprotobuf.a` in the `slib` directory to the `lib` directory of this project (`polaris-php`)
3631

3732
```shell
38-
.
39-
├── doc
40-
│ ├── ApiDoc.md
41-
│ └── HowToBuild.md
42-
├── example
43-
│ ├── polaris_consumer.php
44-
│ ├── polaris_limit.php
45-
│ └── polaris_provider.php
46-
├── include
47-
│ ├── polaris
48-
│ └── utils.hpp
49-
├── lib
50-
│ ├── libpolaris_api.a
51-
│ └── libprotobuf.a
52-
├── php
53-
│ └── php-5.6.40
54-
├── polaris
55-
├── polaris.yaml
56-
├── polaris.yaml.template
57-
└── README.md
33+
cd {One of your directories}/polaris-cpp
5834
```
35+
### Build Polaris PHP
5936

60-
### 构建 Polaris PHP
61-
62-
确保本地默认的`php`版本为`5.6.x`或者为`7.4.x`版本
37+
Make sure that the local default `php` version is `5.6.x` or `7.4.x`
6338

6439
```shell
65-
6640
cd ./polaris
67-
# clean last build info
41+
6842
phpize --clean
6943

7044
phpize
7145

72-
./configure --with-php-config=${php-config 文件的全路径信息} --with-polaris_provider
46+
./configure --with-php-config=${php-config Full path information of the file} --with-polaris_provider
7347

7448
make && make install
7549
```

doc/HowToBuild_ZH.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# How to build
2+
3+
## 前期准备
4+
### 构建 Polaris-CPP
5+
6+
`polaris-cpp`项目`clone`到你本地的一个目录中
7+
8+
```shell
9+
cd {你的一个目录}
10+
# 下载
11+
git clone [email protected]:polarismesh/polaris-cpp.git
12+
13+
# 执行编译构建
14+
15+
make && make package
16+
```
17+
18+
执行make package后会在当前目录下生成一个polaris_cpp_sdk.tar.gz压缩文件。该文件的内容如下:
19+
20+
```
21+
|-- include/polaris # 头文件
22+
| |-- consumer.h provider.h limit.h config.h context.h log.h defs.h ...
23+
|-- dlib # 动态库
24+
| |-- libpolaris_api.so
25+
`-- slib # 静态库
26+
|-- libpolaris_api.a libprotobuf.a
27+
```
28+
29+
对文件`polaris_cpp_sdk.tar.gz`进行解压,将`slib`目录下的`libpolaris_api.a`以及`libprotobuf.a`拷贝到本项目(`polaris-php`)的`lib`目录下
30+
31+
```shell
32+
cd {你的一个目录}/polaris-cpp
33+
```
34+
### 构建 Polaris PHP
35+
36+
确保本地默认的`php`版本为`5.6.40`或者为`7.4.x`
37+
38+
```shell
39+
cd ./polaris
40+
41+
phpize --clean
42+
43+
phpize
44+
45+
./configure --with-php-config=${php-config 文件的全路径信息} --with-polaris_provider
46+
47+
make && make install
48+
```

examples/circuitbreaker/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# CircuitBreaker Example
2+
3+
Based on a simple polaris-php usage example, demonstrate how a php application can quickly use Polaris' service CircuitBreaker.
4+
5+
## How to build
6+
7+
- Build the corresponding polaris-php plugin [Build documentation](../../doc/HowToBuild.md)
8+
9+
## How to Use
10+
11+
### Create Service
12+
13+
- Create the corresponding service through the Polaris console in advance. If it is installed through a local one-click installation package, open the console directly in the browser through 127.0.0.1:8091.
14+
- Create a service provider
15+
- ![create_provider_service](./image/create-php-provider.png)
16+
- Create service provider instance
17+
- ![create_provider_instance](./image/create-php-provider-instance.png)
18+
19+
20+
### Execute program
21+
22+
```shell
23+
php circuitbreaker.php
24+
```
25+
26+
Observe the output
27+
28+
- Output expected value
29+
30+
```
31+
array(3) {
32+
[0]=>
33+
array(19) {
34+
["host"]=> string(9) "127.0.0.2"
35+
["port"]=> int(8080)
36+
...
37+
}
38+
[1]=>
39+
array(19) {
40+
["host"]=> string(9) "127.0.0.1"
41+
["port"]=> int(8080)
42+
...
43+
}
44+
[2]=>
45+
array(19) {
46+
["host"]=> string(9) "127.0.0.4"
47+
["port"]=> int(8080)
48+
...
49+
}
50+
}
51+
```
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# CircuitBreaker Example
2+
3+
根据简单的 polaris-php 使用示例,演示 php 应用如何快速使用北极星的服务熔断功能。
4+
5+
## 如何构建
6+
7+
- 构建对应的 polaris-php 插件, [构建文档](../../doc/HowToBuild_ZH.md)
8+
9+
## 如何使用
10+
11+
### 创建服务
12+
13+
- 预先通过北极星控制台创建对应的服务,如果是通过本地一键安装包的方式安装,直接在浏览器通过127.0.0.1:8091打开控制台。
14+
- 创建服务提供者
15+
- ![create_provider_service](./image/create-php-provider.png)
16+
- 创建服务提供这实例
17+
- ![create_provider_instance](./image/create-php-provider-instance.png)
18+
19+
20+
### 执行程序
21+
22+
```shell
23+
php circuitbreaker.php
24+
```
25+
26+
观察输出结果
27+
28+
- 输出期望值
29+
30+
```
31+
array(3) {
32+
[0]=>
33+
array(19) {
34+
["host"]=> string(9) "127.0.0.2"
35+
["port"]=> int(8080)
36+
...
37+
}
38+
[1]=>
39+
array(19) {
40+
["host"]=> string(9) "127.0.0.1"
41+
["port"]=> int(8080)
42+
...
43+
}
44+
[2]=>
45+
array(19) {
46+
["host"]=> string(9) "127.0.0.4"
47+
["port"]=> int(8080)
48+
...
49+
}
50+
}
51+
```
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
$br = (php_sapi_name() == "cli")? "":"<br>";
3+
4+
if(!extension_loaded('polaris')) {
5+
dl('polaris.' . PHP_SHLIB_SUFFIX);
6+
}
7+
8+
// 创建一个 polaris-provider 实例
9+
$polaris = new PolarisClient(array(
10+
"config_path" => "./polaris.yaml",
11+
"log_dir" => "./"
12+
));
13+
$client_req = array(
14+
"namespace" => "default",
15+
"service" => "polaris-php-provider",
16+
);
17+
18+
$polaris->InitConsumer();
19+
20+
$res = $polaris->GetInstances($client_req, 5000, 1);
21+
var_dump($res);
22+
23+
for ($i=1; $i<=10; $i++)
24+
{
25+
$call_service_result = array(
26+
"namespace" => "default",
27+
"service" => "polaris-php-provider",
28+
"host" => "127.0.0.3",
29+
"port" => "8080",
30+
"ret_status" => "error",
31+
);
32+
33+
$timeout = 500;
34+
$flow_id = 123456;
35+
$res = $polaris->UpdateServiceCallResult($call_service_result, $timeout, $flow_id);
36+
var_dump($res);
37+
sleep(1);
38+
}
39+
40+
$res = $polaris->GetInstances($client_req, 5000, 1);
41+
$instances = $res["response"]["instances"];
42+
var_dump($instances);
43+
?>
107 KB
Loading
382 KB
Loading
194 KB
Loading

0 commit comments

Comments
 (0)