Jump to content

remote server testing using fsockopen: works on 1 machine but not another


Recommended Posts

Ok.  I have taken the EXACT same code (literal cut and paste) from server A to server B.  On sever A it works exactly as expected.  On server B it does not work at all.  Please take a look.

 

<?php

//test the server to see if it's up
$server_testing = @fsockopen ("1.1.1", 80, $errno, $errstr, .2);

if ($server_testing)
{
echo "UP";
}

else
{
echo "DOWN":
}
?>

 

Clearly this code should ALWAYS output "DOWN" as '1.1.1' is not even a valid IP address.  However "server B" ALWAYS says "UP" where as "Server A" ALWAYS says "DOWN"  Is there another function that I can use to attempt to connect to a port?  Does anyone have any idea why this would work on 1 server and not another?

works fine you had an error ok but this checks if goole is up and runninig.

 

<?php

//test the server to see if it's up
$server_testing = @fsockopen ("64.233.167.99", 80, $errno, $errstr, .2);

if ($server_testing)
{
echo "UP";
}

else
{
echo "DOWN";
}
?>

removed the "@" and ran again.  Server A produces errors as expected ("Warning: fsockopen(): unable to connect to 1.1.1:80").  Server B produced nothing at all and still had the output of "UP"

 

Here are the break downs...

(WORKING SERVER) Server A: PHP Version 4.4.2

O.S.:  Linux 2.4.21-32.0.1.ELsmp #1 SMP

 

(NON WORKING SERVER) Server B: HP Version 4.3.11

O.S.: Linux 2.4.21-27.ELsmp #1

 

works fine you had an error ok but this checks if goole is up and runninig.

 

Yes, I am aware that it works fine on google.  My point is that I cannot get my script on "server B" to tell me that a server is DOWN when it obviously is.  If you put a valid IP of a server that is up (like google) it works fine.  However I want it to tell me when a server is down.  BUT it always says it is up..no matter what.

The script works properly here with php 4.3.10-18 (from debian) and 5.1.4 (compiled from source).  The system is running a custom 2.6.8 kernel.

 

What does 'ping 1.1.1' give you on server A and server B?  I'm thinking it may be something to do with the dns setup on server B.  You also might want to try sending data on the "open" socket and see what happens.  Or reading data from it.  Or perhaps try var_dump() the returned resource to see if it really is an open socket.

What does 'ping 1.1.1' give you on server A and server B?

-I do not have SSH access on Server B unfortunatley.  I don't think there is another way to ping from a php script is there?

 

You also might want to try sending data on the "open" socket and see what happens.

-Are you suggesting that I test using the method described by "redarrow" in his/her post?  Cause I know that the script fully works.  I suspect you are hinting at using something like fwrite or something along those lines.  I honestly would have no idea how to write to a file on a different server.

 

Or perhaps try var_dump() the returned resource to see if it really is an open socket.

-I ran var_dump and it returned..  (ALL OF THE FOLLOWING is from the broken *Server B")

"resource(1) of type (stream)"

If I echo $server_testing to the screen I get "Resource id #1"

 

Oddly enough if I repeat the tests the numbers keep on increasing like this...

"resource(2) of type (stream)"

"Resource id #2"

"resource(3) of type (stream)"

"Resource id #3"

 

I believe your comparison wrong, and I'm unsure as to why it works on Server A.

 

fsockopen returns a resource on success, or FALSE on failure.

 

<?php

//test the server to see if it's up
$server_testing = fsockopen ("1.1.1", 80, $errno, $errstr, .2);

if ($server_testing === FALSE)
{
echo "DOWN";
}

else
{
echo "UP":
}
?>

I believe your comparison wrong, and I'm unsure as to why it works on Server A.

 

fsockopen returns a resource on success, or FALSE on failure.

 

Please elaborate.  What do you mean by my "comparison wrong?"

First off might have nothing to do with the the script since it does work.

 

Can you access the HTTP:// of Server B from all outside computers?  80 being the HTTP Server you should be able to load the home page from anywhere with internet access.

 

If not, Server B has Port 80 Blocked either by local router at the server location, blocked by the ISP, or Firewall Software.

 

If B is not blocked then it could be that its not configured for Both Directions in the Firewall Hardware and/or Software.  Can also be that you are blocking ICMP Requests or have Intruder Defense System (IDS) installed that does not see a Browser Tag ID and will reject the request of incoming fsocket inquiry.

 

 

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.