Jump to content

fsock problem - need help


andyk

Recommended Posts

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:


[code]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[/code]


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
Link to comment
Share on other sites

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

[code=php:0]
$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;
  }
}
[/code]

Then if $server['server1'] is 0 the server is down and 1 its up.
Link to comment
Share on other sites

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

Edit:

I've done this.

[code]<?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.?>[/code]

And get this error:

[code]Parse error: syntax error, unexpected T_IF in /home/******/public_html/teamspeak/test.php on line 30[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.