title: Get all Ports On Server BY PHP Code
body: <p>Good day.I was trying to find a php code from where i can get all ports on sever side.The reason is that im using a shared server,shared server does not let me to execute any cmd command and how funny and pathetic it would be on google i did not find any php code which will do this except this one.</p>
  
  <pre><code>$host = 'stackoverflow.com';
  $ports = array(21, 25, 80, 81, 110, 443, 3306);
  
  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>
  
  <p>The problem is that i want to open a socket and accept a socket connection from android but whatever port i try to open,it says that port is in use and by this code im not gettin all ports but only this ones </p>
  
  <pre><code>array(21, 25, 80, 81, 110, 443, 3306);
  </code></pre>
  
  <p>So my quesiton is there any php code which will return me all ports on server with status are they in use or no.Thank you.</p>