Skip to content

Commit a6f8b20

Browse files
committed
docs: fix quickstart/provider/provider.php
1 parent 1c4a7f3 commit a6f8b20

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

examples/quickstart/provider/provider.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99

1010
set_time_limit(0);
1111

12+
13+
$self_ip = getenv('PHP_PROVIDER_IP');
14+
var_dump($self_ip);
15+
1216
class TCPServer
1317
{
14-
private $ip = '127.0.0.1';
1518
private $port = 9996;
1619

1720
private $_socket = null;
@@ -26,7 +29,7 @@ public function __construct()
2629

2730
public function run()
2831
{
29-
$bind_ok = socket_bind($this->_socket, $this->ip, $this->port);
32+
$bind_ok = socket_bind($this->_socket, '0.0.0.0', $this->port);
3033

3134
if ($bind_ok === false) {
3235
echo "socket_bind() failed, reason: ".socket_strerror(socket_last_error())."\n";
@@ -53,6 +56,9 @@ public function close()
5356

5457
$pid = pcntl_fork();
5558
if ( $pid == 0 ) {
59+
$self_ip = getenv('PHP_PROVIDER_IP');
60+
var_dump($self_ip);
61+
5662
// 创建一个 polaris-provider 实例
5763
$polaris = new PolarisClient(array(
5864
"config_path" => "./polaris.yaml",
@@ -65,7 +71,7 @@ public function close()
6571
$register_instance_info = array(
6672
"namespace" => "default",
6773
"service" => "polaris_php_test",
68-
"host" => "127.0.0.1",
74+
"host" => $self_ip,
6975
"port" => "9996",
7076
"heartbeat" => "true",
7177
"protocol" => "TCP",
@@ -80,12 +86,17 @@ public function close()
8086
// 执行实例注册动作
8187
$res = $polaris->Register($register_instance_info, 5000, 1);
8288
var_dump($res);
89+
if ( $res['code'] != '0') {
90+
$err_msg = $res["err_msg"];
91+
echo "register instance fail '$err_msg'";
92+
exit(1);
93+
}
8394

8495
// 实例心跳信息
8596
$heartbeat_info = array(
8697
"namespace" => "default",
8798
"service" => "polaris_php_test",
88-
"host" => "127.0.0.1",
99+
"host" => $self_ip,
89100
"port" => "9996",
90101
);
91102
while (true) {

0 commit comments

Comments
 (0)