Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

verify server is up before link

Status
Not open for further replies.

grnfvr

MIS
Dec 21, 2000
111
US
Is there a way to programmatically ping a server to check that it is up and running before directing an anchor tag to that server.
 
Well, of course there is a way to ping the remote server. It's a little command-line utility called "ping" ;-). And since PHP can call command line utilities, there you go.

What you have to do is use a command like exec() ( or the backtick operator ( this will run your ping command, and return the output as a array, or string variable, which you can examine using some regular expression or string search.

Then, you have to think about what the returned output of ping will look like, and what expression you want to use to evaluate whether the ping is successful or not. You should play around with the ping command on your server. If it is a unix server, enter "man ping".
 
I am fairly new to web programming. My background is mostly visual basic. I honestly have no idea what php is. It appears to be some type of server side scripting. do you know of any good resources i could use to get rolling?
 
Ping will just tell you that there's a connection between the box that initiates the ping, and the remote server that responds to the ping.

With virtual hosting, a multitude of websites could have the same IP address. While the server could respond, the site could still be down (nonpayment, bad permissions, sloppy coding, etc).

In addition, the link could still be a 'dead link' even if the server is up (bad url, typo, etc)

fopen would be the proper solution.

fopen (" "r") or die('Not there!');

If it gets it, great. If it doesn't, no glory.

Good rescources? Depends on how you learn. This site, as well as other forum and code repository sites exist. There are also several books out there to read..
 
If you come from a VB/Microsoft background, you should read thread434-151252. (the ASP->PHP link in this same forum)

PHP is similar to Active Server Pages, except that it is truly cross-platform. PHP runs identically in both Windows and Unix, with some slight variations for some operations that relate to the OS and filesystem. It has a very straightforward, logical structure. Even if you are more familiar with VB, you have probably played around with Javascript some. Well, the good news is that PHP's syntax is very similar to Javascript.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top