Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Use of fsocketopen function to check system status.

shell_exec, fsockopen, system online/offline



10:52 am on Jun 18, 2008 (gmt 0)

5+ Year Member

Dear All!

I have a small problem. I want to write a PHP Application that will run on server and will check weather the compter systems in its network are online/offline.

I have acheived the desired result using ping cammand
shell_exec("ping -r -c 1 -W 1 $ip");

It works fine but is a bit slow.

I was looking at various options and found this PHP function fsockopen(). I wanted to know waether it could help me in achieving what i want. Is this a right option for doing such thing?

I have seen few tutorials but still am confused. Could not understood it properly. Can anyone help how to use it?

Thanks in Advance



1:21 pm on Jun 18, 2008 (gmt 0)

10+ Year Member

Hi Qasim,

the main difference to ping is that `ping` is using the ICMP protocol, while fsockopen() does not but can do TCP or UDP connects.

So, using fsockopen(), you may connect to a server port and test a service - which is even better than a ping, as a ping shows that the TCP/IP stack of the target is basically working, while a service connect explicitly shows if a specific service is working, or is dead.

Manual and examples here:

Kind regards,


3:35 am on Jun 19, 2008 (gmt 0)

5+ Year Member

Hi Romeo!

Thanks a lot. Thats great. In my case since i need to check weather a system is online/offline, what service should i check using fsockopen(). It will be great if u provide a small example.



12:57 pm on Jun 19, 2008 (gmt 0)

10+ Year Member


the link to php.net has a lot of examples to check a webserver or connect to a mail server.

You will learn a lot by trying some of these examples.

If you would like to test the pure connectivity only and not communicate with the service at such, it may perhaps be sufficient to just look at the status of the fsockopen to decide if a service is connectable:
$fp = fsockopen(.....);
if (!$fp) { # no connect!

Good luck and
kind regards,


4:53 am on Jun 27, 2008 (gmt 0)

5+ Year Member

Thanks Romeo!

Featured Threads

Hot Threads This Week

Hot Threads This Month