LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-02-2001, 09:09 AM   #1
cbe
LQ Newbie
 
Registered: Jul 2001
Posts: 19

Rep: Reputation: 0
php - fsockopen


Hello,
I was wondering if someone could help me.
I am using a php script to show whether another server is online
and when the server "is" down it takes forever to load the page.

the first script I used first used ping and it was quite fast, but since I moved servers they dont allow ping - ping has to be run as root.
so I tried a few different things till I settled with this script:

<?php
$fp = fsockopen ("IP.address.of.server", 80);
if (!$fp) {
?>

<b>Server is Offline</b>

<?
}
else
{
?>

<a href="http://address">Link is UP</a>

<?
}
?>

Is there a better or faster way to do this? or am I stuck?
the script above resides on a Cobolt Raq if that would help.

Thanks for any help you can provide,
Cbe
 
Old 07-16-2001, 05:30 PM   #2
gizmola
Member
 
Registered: Jun 2001
Location: Los Angeles, CA USA
Distribution: RedHat
Posts: 53

Rep: Reputation: 15
Re: php - fsockopen

Quote:
Originally posted by cbe
Hello,
I was wondering if someone could help me.
I am using a php script to show whether another server is online
and when the server "is" down it takes forever to load the page.

the first script I used first used ping and it was quite fast, but since I moved servers they dont allow ping - ping has to be run as root.
so I tried a few different things till I settled with this script:

<?php
$fp = fsockopen ("IP.address.of.server", 80);
if (!$fp) {
?>

<b>Server is Offline</b>

<?
}
else
{
?>

<a href="http://address">Link is UP</a>

<?
}
?>

Is there a better or faster way to do this? or am I stuck?
the script above resides on a Cobolt Raq if that would help.

Thanks for any help you can provide,
Cbe
I see that u are trying to open a socket connection to port 80 for all these servers, and I might point out, that if you are intending to monitor the state of webservers on this machine, then that is great, but a a webserver could be down, and the machine still be up. I only point this out, because it is completely different than what the ping program does, since that uses icmp, which is not directly or indirectly supported from within php.

Nevertheless, your best chance for speeding up the page is to attempt to shorten the blocking that occurs when you hit a server that is down, and the webserver sits waiting for a connection that is not going to work. Notice the last paramter on the fsockopen call? Set that to 1 for 1 second, and a connect attempt will timeout after 1 second.

int fsockopen (string [udp://]hostname, int port [, int errno [, string errstr [, double timeout]]])
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with fsockopen javier_ccs Programming 1 08-25-2005 11:55 AM
php apache or php cgi - php learner rblampain Linux - Security 3 12-17-2004 11:10 PM
why fsockopen() use root dns info?? - about php chtla Linux - Software 0 04-13-2004 11:42 PM
Php Fsockopen jinksys Programming 0 02-08-2004 06:04 AM
PHP - fsockopen() + Redhat8 aspr Linux - Networking 0 06-03-2003 03:15 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration