Php code to ping a website

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
srirams
Forum Commoner
Posts: 36
Joined: Wed May 25, 2005 8:57 am
Location: India
Contact:

Php code to ping a website

Post by srirams »

All,

Can anyone tell me a way where I can ping a particular site to see if it is up or not.
For example, if I gave a URL in the code it should check if the site is up and running or not.
If someone can explain this with an example code it would be great.

Thanks in advance.
Syranide
Forum Contributor
Posts: 281
Joined: Fri May 20, 2005 3:16 pm
Location: Sweden

Post by Syranide »

Using ping would be awfully missguiding, could likely even not work due to blocked pings. What you want to do would be to simply connect to it's port 80 and see if it responds, or something like that.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

fsockopen()

Hint: If my memory serves me correctly there's an example written by someone in a thread at the bottom....

If not you essentially try to open a socket on port 80 (use @ at the front to surpess error output) and test if it returns true or false.... :wink:

EDIT | My memory served me wrongly... the there's a tutorial on Spoono.com for this (see link in my signature)...
hairyjim
Forum Contributor
Posts: 219
Joined: Wed Nov 13, 2002 9:04 am
Location: Warwickshire, UK

Post by hairyjim »

d11wtq wrote: EDIT | My memory served me wrongly... the there's a tutorial on Spoono.com for this (see link in my signature)...
Oh yeah! really good tutorials.

I really like the ones that take you through creating something useful, gives me a better understanding of how to use things in the 'real world' environment.
Post Reply