curl and ping - how to check whether a website is either up or down?
something like this should work
$url = 'yoururl';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
$retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if (200==$retcode) {
// All's well
} else {
// not so much
}
How can I make this online site checker work?
One of the misunderstandings of the classic if errorlevel 0
command,
which translates to (see help if)
if errorlevel is 0 or greater
which is always true for positive errorlevels.
Either
- check
if errorlevel 1
and reverse the logicif errorlevel 1 (GOTO :downwarning) else (GOTO :upwarning)
- check for the current value of
%errorlevel%
if %errorlevel%==0 (GOTO :upwarning) else (GOTO :downwarning)
- use conditional execution on success/fail
&&/||
curl -i http://www.google.com/ 1> statusgoogle.txt
findstr /c:"Connection established" statusgoogle.txt &&(GOTO :upwarning)||(GOTO :downwarning)
:upwarning
echo site up
goto :eof
:downwarning
echo site down
Checking if a website exists
You could simply use HEAD request to get only the headers of the page and not the whole page. Still, the website will still generate the full page but at least you won't download everything.
To achieve this, you can use many methods, just check how to change the headers of the request and instead of doing a GET, you can do a HEAD.
Fastest way to ping thousands of websites using PHP
You can either fork your php process using pcntl_fork
or look into curl's built-in multi-threading. https://web.archive.org/web/20091014034235/http://www.ibuildings.co.uk/blog/archives/811-Multithreading-in-PHP-with-CURL.html
Related Topics
Access Denied for User @ 'Localhost' to Database ''
Is It Secure to Store a Password in a Session
Merge 'With' and 'Wherehas' in Laravel 5
The Csrf Token Is Invalid. Please Try to Resubmit the Form
Remove Xml Version Tag When a Xml Is Created in PHP
Checking If Your Code Is Running on 64-Bit PHP
How to Check If an Uploaded File Is an Image Without Mime Type
How to Access PHP Session Variables from Jquery Function in a .Js File
Getting Data with Utf-8 Charset from Mssql Server Using PHP Freetds Extension
Can You Append Strings to Variables in PHP
Laravel Error: Missing Required Parameters for Route
Access Variables from Parent Scope in Anonymous PHP Function
Get Most Recent Date from an Array of Dates in "Y-M-D H:I:S" Format
How to Bind Multiple Parameters to MySQLi Query