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:
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.
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.