Reputation: 1985
Are there any methods to get my server IP? I am writing a command where I need my server IP as parameter?
Tried request_stack
but it doesn't work as I expected.
Upvotes: 1
Views: 672
Reputation: 15010
I think you can request an external resource that return your server IP, you can do this with this code in a Symfony command:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'ipinfo.io/ip');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$ip = curl_exec($ch);
I hope this can help you
Upvotes: 1