Sometime this is need to know that some port is active or not cause a port is used to recognize a specific service which is being executed in a computer. To recognize a port and to send packets, 16 bit numbers known as port numbers are used. A port number along with IP address serves as a destination for packets to be sent.
Suppose domain name https://techparkbd.com/ so get this ip address so ip is 220.127.116.11. There are many website to know ip. Then check port that open or not.
$host_connection = '18.104.22.168'; // techparkbd
$ports_number = array(21, 25, 80, 81, 110,143, 443, 3306); //checking port number
foreach ($ports_number as $port)
$connection_check = @fsockopen($host_connection, $port);
echo '<h5>' . $host_connection . ':' . $port . ' ' . '(' . getservbyport($port, 'tcp') . ') is open now.</h5>' . "\n";
echo '<h5 style="color: red">' . $host_connection . ':' . $port . ' is not open now.</h5>' . "\n";
when you run this code it will show result like this
22.214.171.124:21 (ftp) is open now.
126.96.36.199:25 (smtp) is open now.
188.8.131.52:80 (http) is open now.
184.108.40.206:81 is not open now.
220.127.116.11:110 (pop3) is open now.
18.104.22.168:143 (imap) is open now.
22.214.171.124:443 (https) is open now.
126.96.36.199:3306 () is open now.
This is very simple way to know port open or not. If you face any problem then please inform me.