Check port is open and not open using PHP

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.

You can check port number open or not using simple php code

$host_connection = ''; // domain name
$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);

if (is_resource($connection_check))
echo '<h5>' . $host_connection . ':' . $port . ' ' . '(' . getservbyport($port, 'tcp') . ') is open now.</h5>' . "\n";


echo '<h5>' . $host_connection . ':' . $port . ' is not open now.</h5>' . "\n";


	 20, 21:  For FTP (File transfer protocol)
	 22: For SSH (Secure Shell)
	 23: For remote login (Telnet)
	 25: For SMTP (Simple mail transfer protocol)
	 53: For DNS (Domain Name System)
	 80: For World Wide Web
	 110: For POP3 (Post office protocol)
	 143: For IMAP (Internet Message Access Protocol)
	 194: For IRC (Internet relay chat)
	 443: For HTTPS (HTTP secure)
	 532: For Usenet newsgroups
     3306: MYSQL database system

For any query please leave a comment.


About shafiqul
I am Shaikh Shafiqul Islam.I am working as a software engineer at Premium Web Cart in Bangladesh. I had completed my B.SC majoring Computer Science and Engineering in 2010 at the Dept of CSE in Ruet(Rajshahi University of Engineering & Technology), a leading engineering university of Bangladesh. I want to explore myself with latest technology and also want to develop my Career with well-established and fast growing IT Industry in Bangladesh. I started this blog to keep all the interesting PHP, HTML,Javascript,Ajax, Jquery related information.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


Web Development Resource

UI and UX Design

User Interface and User Experience


code,Tips,Tricks in php,mysql,javascript,jquery,ajax,yii,yii2,codeigniter,laravel,drupal,slim,bootstrap,api,jQuery Mobile

%d bloggers like this: