Checking if a port is open?

What's a good way to check if a port is open in php?  I'm trying to write a script that makes sure a server is online.
gunghoassassinAsked:
Who is Participating?
 
Diablo84Connect With a Mentor Commented:
A simple method would be using fsockopen (http://www.php.net/manual/en/function.fsockopen.php)

eg.

<?php
$url = "http://www.domain.com";
$port = 80;
$fp = fsockopen($url, $port);
if (!$fp) {
 echo "server offline";
}
?>
0
 
Diablo84Commented:
Be sure to check out the manual page (see link above) and the user comments at the bottom of the page for more examples of the functions use
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.