walkor / workerman

An asynchronous event driven PHP socket framework. Supports HTTP, Websocket, SSL and other custom protocols.
http://www.workerman.net
MIT License
11.12k stars 2.26k forks source link

No way to get Server IP and Port directly #921

Closed joanhey closed 1 year ago

joanhey commented 1 year ago

Hi, Walkor

I want to add $_SERVER['SERVER_ADDR'] to Adapterman, but I can't find a direct way to get it.

I can create it in the Http.php, from Worker->socketName. But perhaps it will be better to be in the Worker.php, as it's useful in many apps.

@walkor What do you think is the best way or alternative ?

walkor commented 1 year ago

Create it in Http.php like this.

public function decode($buffer, $connection) {     $_SERVER[‘SERVER_ADDR’] = $connection->getRemoteIp();

}

------------------ Original ------------------ From: Joan Miquel @.> Date: Wed,Jun 28,2023 6:25 PM To: walkor/workerman @.> Cc: walkor @.>, Mention @.> Subject: Re: [walkor/workerman] No way to get Server IP and Port directly (Issue #921)

Hi, Walkor

I want to add $_SERVER['SERVER_ADDR'] to Adapterman, but I can't find a direct way to get it.

I can create it in the Http.php, from Worker->socketName. But perhaps it will be better to be in the Worker.php, as it's useful in many apps.

@walkor What do you think is the best way or alternative ?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

joanhey commented 1 year ago

Hmmm; getRemoteIP() is the ip of the client, not the Server IP.

Update: Connection also have getLocalIp() and getLocalPort(). It isn't very fast, but we will update it later.