Aipo
Aipo

Reputation: 1985

How to get my server IP in Symfony Command?

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

Answers (1)

Jose M. González
Jose M. González

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

Related Questions