title: PHP fsockopen() fails does not open port but telnet works
body: <p>I am facing a weird network problem trying to resolve for the last 2 days. I can not get to open the port 25003 on php web page. The code does not seem to be a problem, however, its as given below.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>$host = 'xx.xx.xx.xx';    // statis public ip address assigned by my isp
  $ports = array(80, 25003);
  
  foreach ($ports as $port)
  {
      $connection = fsockopen($host, $port);
  
      if (is_resource($connection))
      {
          echo '&lt;h2&gt;' . $host . ':' . $port . ' ' . '(' . getservbyport($port, 'tcp') . ') is open.&lt;/h2&gt;' . "\n";
  
          fclose($connection);
      }
  
      else
      {
          echo '&lt;h2&gt;' . $host . ':' . $port . ' is not responding.&lt;/h2&gt;' . "\n";
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>Port 80 shows open but not port 25003.</p>
  
  <p>The site is hosted on Bluehost shared hosting plan with a static IP too. Cross verified with them more than 3 times the fact that port 25003 is open on both incoming and outgoing connections. Would they be lying, I don't think so.</p>
  
  <p>On client PC settings :</p>
  
  <pre><code>(1) Firewall is disabled for testing purpose.
  
  (2) Port forwarding is done correctly in router. I assume so because
   I can easily telnet MY PUBLIC IP with a port 25003 within the same
   LAN and from phone using sim card's internet.
  
  (3) I did a port check from https://ping.eu/port-chk/ and it shows open.
  
  (4) Client PC has a serproxy installed for serial to IP &amp; Port.
  (5) When I do a port check from above link, serproxy shows following message which seems to be okay on its part.
        * server thread launched
        * server(1) - thread started
        * server(1) - EOF from sock
        * server(1) - Exiting
  
  (6) Again, when I telnet from external lan, it shows above message in Client PC's Serproxy which means it is doing its work properly. And it shows correct data from serial port to cmd line while telneting. 
  </code></pre>
  
  <p>The problem is when I fsockopen using above pieces of code, it says CONNECTION REFUSED.</p>
  
  <p>Below is my actual code which should try to connect and read data from serial port but CONNECTION REFUSED.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>$fp = fsockopen("tcp://xx.xx.xx.xx", 25003, $errno, $errstr);
  if (!$fp) {
      echo "$errstr ($errno)&lt;br /&gt;\n";
  } else {
      if (!feof($fp)) {
          $weight = trim(fgets($fp, 64)," ");
      }
  }
  echo $weight;
   fclose($fp);</code></pre>
  </div>
  </div>
  </p>
  
  <p>I think the problem lies either in bluehost shared server or client windows PC or SERPROXY or local network configuration. I am afraid there is any major config change possible other than baud rate, com port etc in the SERPROXY which is set correctly.</p>
  
  <p>I am now totally clueless as to how to resolve the said problem. If somebody could help will be greatly appreciated. </p>
  
  <p>I would share the public IP if somebody wants to check the connectivity.</p>