Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

I am trying to access my ec2's public hostname from inside the instance.

I would like to run this command

curl http:// 169 254.169.254/latest/meta-data/public-hostname

inside a php script and save the response to a variable. How can I do this?

1 Answer

0 votes
by (44.4k points)

Do something like this and change the URL to your targeted site:

<?php  

//URL of targeted site  

$url = "http://www.example.com/";  

$ch = curl_init();  

// set URL and other appropriate options  

curl_setopt($ch, CURLOPT_URL, $url);  

curl_setopt($ch, CURLOPT_HEADER, 0);  

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  

// grab URL and pass it to the browser  

$output = curl_exec($ch);  

//echo $output;

// close curl resource, and free up system resources  

curl_close($ch);  

?>  

So, $output variable has the response.

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
4 answers
asked May 9, 2021 in Python by laddulakshana (16.4k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...