cunoodle2 Posted February 13, 2007 Share Posted February 13, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/38264-remote-server-testing-using-fsockopen-works-on-1-machine-but-not-another/ Share on other sites More sharing options...
btherl Posted February 13, 2007 Share Posted February 13, 2007 Which operating system and versions of php are running on these servers? You might want to remove the @ as well, so you can get any error messages. Quote Link to comment https://forums.phpfreaks.com/topic/38264-remote-server-testing-using-fsockopen-works-on-1-machine-but-not-another/#findComment-183332 Share on other sites More sharing options...
redarrow Posted February 13, 2007 Share Posted February 13, 2007 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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/38264-remote-server-testing-using-fsockopen-works-on-1-machine-but-not-another/#findComment-183338 Share on other sites More sharing options...
cunoodle2 Posted February 13, 2007 Author Share Posted February 13, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/38264-remote-server-testing-using-fsockopen-works-on-1-machine-but-not-another/#findComment-183345 Share on other sites More sharing options...
btherl Posted February 13, 2007 Share Posted February 13, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/38264-remote-server-testing-using-fsockopen-works-on-1-machine-but-not-another/#findComment-183448 Share on other sites More sharing options...
cunoodle2 Posted February 13, 2007 Author Share Posted February 13, 2007 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" Quote Link to comment https://forums.phpfreaks.com/topic/38264-remote-server-testing-using-fsockopen-works-on-1-machine-but-not-another/#findComment-183458 Share on other sites More sharing options...
cunoodle2 Posted February 14, 2007 Author Share Posted February 14, 2007 Bumping to the top to see if anyone has any more input. I still cannot get this to work. Quote Link to comment https://forums.phpfreaks.com/topic/38264-remote-server-testing-using-fsockopen-works-on-1-machine-but-not-another/#findComment-184707 Share on other sites More sharing options...
Balmung-San Posted February 14, 2007 Share Posted February 14, 2007 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": } ?> Quote Link to comment https://forums.phpfreaks.com/topic/38264-remote-server-testing-using-fsockopen-works-on-1-machine-but-not-another/#findComment-184726 Share on other sites More sharing options...
cunoodle2 Posted February 15, 2007 Author Share Posted February 15, 2007 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?" Quote Link to comment https://forums.phpfreaks.com/topic/38264-remote-server-testing-using-fsockopen-works-on-1-machine-but-not-another/#findComment-185778 Share on other sites More sharing options...
cunoodle2 Posted February 22, 2007 Author Share Posted February 22, 2007 Anyone have any idea? This topic has been active now for 9 days without a solution. Quote Link to comment https://forums.phpfreaks.com/topic/38264-remote-server-testing-using-fsockopen-works-on-1-machine-but-not-another/#findComment-191091 Share on other sites More sharing options...
TRI0N Posted February 22, 2007 Share Posted February 22, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/38264-remote-server-testing-using-fsockopen-works-on-1-machine-but-not-another/#findComment-191124 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.