Page 1 of 1
Can you test a web site's running, from a remote site?
Posted: Mon Apr 08, 2013 4:50 pm
by simonmlewis
I need to run a simple script that checks a web site is running.
If it does NOT load, it need to do something (which I can do - like an email).
It's basically a remote means of making sure a site is running. And if it's down for more than a minute or 3, it fires me an email.
It would rn thru a Cron file. But I've no idea what PHP script would check a site loads, and if it does NOT load, what output format that would come in.
Re: Can you test a web site's running, from a remote site?
Posted: Mon Apr 08, 2013 5:19 pm
by requinix
There are services out there that can do this for you. Like
Pingdom, to name one off the top of my head. It has a free plan that might provide all you need.
Re: Can you test a web site's running, from a remote site?
Posted: Mon Apr 08, 2013 5:26 pm
by simonmlewis
Thanks. Is there no php script that can be run to test a url runs a page?
Re: Can you test a web site's running, from a remote site?
Posted: Mon Apr 08, 2013 7:37 pm
by requinix
You can, but why reinvent the wheel and manufacture them yourself?
Re: Can you test a web site's running, from a remote site?
Posted: Tue Apr 09, 2013 3:15 am
by simonmlewis
Because I have complete control of it.
I can then make it send me an email when a site goes down, and if I choose, I can make the script check multiple sites.
So if you can - how ?
Re: Can you test a web site's running, from a remote site?
Posted: Tue Apr 09, 2013 12:48 pm
by requinix
Are you also a mechanic? Farmer? Doctor? As one programmer who would much rather reinvent the wheel than accept one from a third party to another, sometimes it's worth letting someone else with more knowledge and experience take over.
cURL is the go-to for pretty much everything more complicated than downloading a page from a website. Set a connection timeout of a second or two (should be nearly instant), a timeout of a few seconds longer than your site should take, and check that the site returns a 200 response code. For the URL, pick a page you know will test your site, like one that uses PHP code and hits the database. If it fails you can mail() yourself.
Then set up a cronjob to run however often you want.
Re: Can you test a web site's running, from a remote site?
Posted: Tue Apr 09, 2013 3:14 pm
by simonmlewis
A mechanic???
I have looked up cURL and cannot see what you mean. I often find on here some helpers try to help without helping.
I just need a means to test a page works within a timeout. Curl sounds fine, but how?
Re: Can you test a web site's running, from a remote site?
Posted: Tue Apr 09, 2013 5:04 pm
by pickle
Nagios is a pretty powerful system
Re: Can you test a web site's running, from a remote site?
Posted: Tue Apr 09, 2013 6:08 pm
by requinix
And I often find on forums that people want to receive code rather than advice and suggestions. I'll tell you what to do but I won't give you the code to do it.
curl_setopt() is the most important function. Look at
the manual for the big giant list of possible options you can pass, then check
the examples and
the user notes to see how it's used. Once you get a feel for it, the options you actually need are CURLOPT_TIMEOUT for the overall timeout and CURLOPT_CONNECTTIMEOUT for the connection timeout.
When you execute the request you've built up, cURL will return true or false if it worked. If it did then you also need to check the HTTP code returned: use
curl_getinfo for that (it should always ==200).
Re: Can you test a web site's running, from a remote site?
Posted: Wed Apr 10, 2013 2:32 am
by simonmlewis
Well I don't know Curl at all, and those scripts are often very difficvult to follow, so it's often useful for someone to say: here's how to write it. And here's what each bit means.
I guess you dont' like tutorials that really help.
Thank you.