0

I want to get page status code.

Url address has a port and after that alias:

http://93.184.216.xxx:3000/status

I tried this this:

function status($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, true);    // we want headers
curl_setopt($ch, CURLOPT_NOBODY, true);    // we don't need body
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT,10);
$output = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpcode == 200) { return '<span class="green-link">ONLINE</span>';}
else {

    return '<span class="red-link">'.$httpcode.'</span>';}
}

But this is useless, I'm always get status 0.

Can anybody have better idea? Thanks

Aleksandar
  • 59
  • 1
  • 7
  • Does this answer your question? [Unable to make php curl request with port number](https://stackoverflow.com/questions/7188988/unable-to-make-php-curl-request-with-port-number) – naszy Dec 28 '19 at 22:16
  • No, doesn't work. I'm still getting status 0. – Aleksandar Dec 28 '19 at 22:43
  • Your code works when I run it locally. What URL are you using, I used https://www.google.com and it works fine. If I change the argument to https://www.googl2354345345345345e.com it returns a 0. Are you sure the website exists? Maybe try curl_setopt($ch, CURLOPT_PORT, 3000); and remove the port from the argument. – cnizzardini Dec 28 '19 at 23:00
  • Yes I can open this website on browser normaly. But curl give me status 0. Maybe another solution wget or something similar? – Aleksandar Dec 29 '19 at 01:54
  • It can be something like a firewall blocking your requests going out from the server... Are you able to get a correct response with a different host (e.g. google.com)? You may also try to investigate the error using [curl_error](https://stackoverflow.com/questions/3987006/how-to-catch-curl-errors-in-php) – naszy Dec 29 '19 at 14:29
  • Yes, all sites or hosts works if doesnt have a port in url – Aleksandar Jan 01 '20 at 22:49

0 Answers0