Jump to content


Photo

fsock problem - need help


  • Please log in to reply
3 replies to this topic

#1 andyk

andyk
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 04 October 2006 - 04:43 AM

hello everyone.

I have a problem with a paticular php file, that displays
information from another server. uses the fsock function to
connect, though it doesn't connect. I only get this following error:


Warning: fsockopen() [function.fsockopen]: unable to connect to 202.60.74.149:27034 
(Connection refused) in /home/******/public_html/teamspeak/ts_status.php on line 27
Cannot connect


The server IP Address to connect is : 202.60.74.149
and the port is 27034. we have double checked this numerous times.
We have tried this on 2 different servers. 1 server with PHP version 4.3.11 and the other with the latest, 5.X. no difference.

Is there something I have to enable or my host to enable?
Im quite baffled here. Hope someone can help.

Thanks

Andy

#2 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 04 October 2006 - 04:48 AM

My favorite code for checking server status's that i came across a while back is:

	$IP = array(
  "server1" => "<serv1_ip>:<serv1_port>",
  "server2" => "<serv2_ip>:<serv2_port>",
);
while(list($ServerName,$Host)=each($IP))
 {
  list($IPAddress,$Port)=explode(":",$Host);
  if($fp=fsockopen($IPAddress,$Port,$ERROR_NO,$ERROR_STR,(float)0.5))
  {
   $server[$ServerName]=1;
   fclose($fp);
  }
  elseif($fp=fsockopen($IPAddress,$Port,$ERROR_NO,$ERROR_STR,(float)0.5))
  {
   $server[$ServerName]=1;
   fclose($fp);
   }
  else{
   $server[$ServerName]=0;
  }
 }

Then if $server['server1'] is 0 the server is down and 1 its up.
Why doesn't anyone ever say hi, hey, or whad up world?

#3 andyk

andyk
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 04 October 2006 - 04:55 AM

Im not a full programmer. Only know bits and pieces.
What do I do with this code?

Edit:

I've done this.

<?php $IP = array(
  "server1" => "<202.60.74.149>:<27034>",
  "server2" => "<serv2_ip>:<serv2_port>",
);
while(list($ServerName,$Host)=each($IP))
 {
  list($IPAddress,$Port)=explode(":",$Host);
  if($fp=fsockopen($IPAddress,$Port,$ERROR_NO,$ERROR_STR,(float)0.5))
  {
   $server[$ServerName]=1;
   fclose($fp);
  }
  elseif($fp=fsockopen($IPAddress,$Port,$ERROR_NO,$ERROR_STR,(float)0.5))
  {
   $server[$ServerName]=1;
   fclose($fp);
   }
  else{
   $server[$ServerName]=0;
  }
 }

Then if $server['server1'] is 0 the server is down and 1 its up.?>

And get this error:

Parse error: syntax error, unexpected T_IF in /home/******/public_html/teamspeak/test.php on line 30


#4 thedarkwinter

thedarkwinter
  • Members
  • PipPipPip
  • Advanced Member
  • 191 posts
  • LocationLondon

Posted 04 October 2006 - 08:37 AM

hi

just a point: are you trying to connect to a secure server?

you may need to

fsockopen("ssl://202.60.74.149","27034"....
or
fsockopen("https://202.60.74.14...49","27034"....

cheers,
tdw
Remember - if you don't figure it out yourself, you'll probably forget it tomorrow :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users