Jump to content

fsockopen() wont open url/port of current web server??


lpglycerine

Recommended Posts

Hi,

 

I've been dealing with this issue for about 6 hours now and I'm ready to this stupid computer out the window.

 

I have two computers that I use to test my php scripts, with two separate ISP's so I can check locally (192.168.1.10) and check remotely (www.ourstream.net)

 

All I'm trying to do is check if a certain port is open on my web server.  So, I use fsockopen() to check.. and it works on the local machine, but not on the remote machine. I cannot find what is wrong with my code I have tried everything. If I check on the remote computer to see if port 80 is open on 'www.google.com', it will succeed! If I check to see if port 80 is open on 'www.ourstream.net' it will fail. please please help

 

....

<?php

 

$site = $_SERVER['HTTP_HOST'];

$port = 80;

 

$fp = @fsockopen($site, $port, $errno, $errstr, 10);

 

if(!$fp){

  echo "<b>The port is NOT open!</b>";

}else{

  echo "<b>The port is open!</b>";

  fclose($fp);

}

?>

 

Try this:

 

<?php

$site = gethostbyname($_SERVER['HTTP_HOST']);
$port = 80;

$fp = @fsockopen($site, $port, $errno, $errstr, 10);

if(!$fp){
  echo "<b>The port is NOT open!</b>";
}else{
  echo "<b>The port is open!</b>";
  fclose($fp);
}
?>

 

url read: http://uk3.php.net/fsockopen

 

try this aswell

 

<?php
$fp = fsockopen("www.google.com", 80, $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)<br />\n";
} else {
    $out = "GET / HTTP/1.1\r\n";
    $out .= "Host: www.google.com\r\n";
    $out .= "Connection: Close\r\n\r\n";

    fwrite($fp, $out);
    while (!feof($fp)) {
        echo fgets($fp, 128);
    }
    fclose($fp);
}
?>

Can u tell us what ur doing please..........

 

 

USING TCP 30 NOT TCP 10

 

function works this way...

 

<?php

$site = "www.google.com";//works

//$site = "www.goggle.com";//dont work unknown url non existent

$port = 80;

$fp = fsockopen($site, $port, $errno, $errstr, 30);

if(!$fp){
  echo "<b>The port is NOT open!</b>";
}else{
  echo "<b>The port is open!</b>";
  fclose($fp);
}

?>

I just tried both suggestions and they both result in the same error. google.com will return true whereas the current website address will time out and give the following error...

 

-----

 

Warning: fsockopen() [function.fsockopen]: unable to connect to www.ourstream.net:80 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ) in C:\...

 

Fatal error: Maximum execution time of 30 seconds exceeded in C:\...

your tieland host is a bit crapy mate there dns is well mashed lol........

 

 

 

<?php

$site = "202.149.98.245";

$port = 80;

$fp = fsockopen($site, $port, $errno, $errstr, 30);

if(!$fp){
  echo "<b>The port is NOT open!</b>";
}else{
  echo "<b>The port is open!</b>";
  fclose($fp);
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.