Solved

Checking if a port is open?

Posted on 2004-08-17
2
870 Views
Last Modified: 2007-12-19
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.
0
Comment
Question by:gunghoassassin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 27

Accepted Solution

by:
Diablo84 earned 500 total points
ID: 11821908
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
 
LVL 27

Expert Comment

by:Diablo84
ID: 11821929
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question