dongwen7187 2015-04-15 11:01
浏览 46
已采纳

PHP - Amazon Elastic Beanstalk - 获取私有IP地址

I am hosting a web app in Amazon Elastic Beanstalk (EB). The web app is written in php. EB also uses Elastic Load Balancer (ELB). The web app implements a websocket with the client. Here is what I have done so far:

  1. I know I have to listen to the private ip, not 127.0.0.1 of the instance for this to work
  2. implemented a listener in load balancer to connect to the instance port
  3. opened inbound and outbound traffic for the port in security groups.

If the EB deployment goes for horizontal scaling (increase the number of instances), will the private ips of the scaled instances remain same (please explain)? If not, and I believe so, how do I get the private ip address of the current instance that is serving the client?

So far its working perfectly without any problem, but there's only one instance running. I tried listing the clients and I can get the private ips with the list but I don't know how to identify the instance that is currently serving the file.

Please help me.

  • 写回答

1条回答 默认 最新

  • dougou6114 2015-04-15 12:17
    关注

    This will do the trick:

    <?php $ip = shell_exec('hostname -i'); ?>
    

    important: this works only for the linux environment. For windows, hostname -i is not valid. You can refer to https://superuser.com/questions/382265/ for further ideas.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部