Does anybody known how i can check a website status (if offline/offline) with CURL?! something if*curl_exec* will only tell me that the curl was executed not that website return a 200 status code, or if the domain name doesn't exists, or server return me a 404 status code
function fetch_url_status($url, $followlocation = true) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $followlocation ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_exec($ch); $info = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return $info; } PHP:
from the function above it will give you an array of information.. from the above the array is $info To get the URL status or request code you can use $info["http_code"] 200 for ok, 301 and 302 for redirected and etc... more info php.net/manual/en/function.curl-getinfo.php
Just one problem ... for an invalid domain name like softgroups22.com it will return status code 200 only for softgroups.com/invalidpage.html will return 404 code...
Umm no? It will return 0 for invalid domain names. echo fetch_url_status('http://www.softgroups22.com/'); PHP: Gives me 0.
That's strange. Try echoing the HTML. $ch = curl_init('http://www.softgroups22.com/'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_exec($ch); curl_close($ch); PHP: Just to see what you get...
Err... that's an error on your server then. This is not a normal cURL behavior. Seems more like some kind of browser is being used or something...
How curl will behave when you try to output html code from an non existing domain name? won;t it output a page with "Server not found",etc?!
No, this message is generated by your browser. You'll get a different looking message on each browser. cURL won't return any output at all if there's no server found.