homepage Welcome to WebmasterWorld Guest from 54.226.80.196
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Use of fsocketopen function to check system status.
shell_exec, fsockopen, system online/offline
qasimali82




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

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

Best,
Qasim

 

Romeo




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

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:
[php.net...]

Kind regards,
R.

qasimali82




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

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.

Best,
Qasim

Romeo




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

Qasim,

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,
R.

qasimali82




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

Thanks Romeo!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved