Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8391629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:18:50+00:00 2026-06-09T19:18:50+00:00

I am trying to implement a PHP script that will ping an IP on

  • 0

I am trying to implement a PHP script that will ping an IP on a specific port and echo out whether the server is online / offline. This way, users will be able to see if non-access to the server is a server fault or a own network problem.

The site is currently on http://Dev.stevehamber.com. You can see the “Online” is wrapped in a class of ‘PHP’ and I need this to reflect if the server is online or offline. The application runs on port TCP=25565 so I need the output to show if this port is reachable or not.

Here is a snippet I found that is (I suppose) what I’m looking for:

<?php

$host = 'www.example.com';
$up = ping($host);

// if site is up, send them to the site.
if( $up ) {
        header('Location: http://'.$host);
}
// otherwise, take them to another one of our sites and show them a descriptive message
else {
        header('Location: http://www.anothersite.com/some_message');
}

?>

How can I replicate something like this on my page?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T19:18:51+00:00Added an answer on June 9, 2026 at 7:18 pm

    Based on the comments on the question, fsockopen() is the simplest and most widely available way to accomplish this task.

    <?php
    
        // Host name or IP to check
        $host = 'www.example.com';
    
        // Number of seconds to wait for a response from remote host
        $timeout = 2;
    
        // TCP port to connect to
        $port = 25565;
    
        // Try and connect
        if ($sock = fsockopen($host, $port, $errNo, $errStr, $timeout)) {
            // Connected successfully
            $up = TRUE;
            fclose($sock); // Drop connection immediately for tidiness
        } else {
            // Connection failed
            $up = FALSE;
        }
    
        // Display something    
        if ($up) {
            echo "The server at $host:$port is up and running :-D";
        } else {
            echo "I couldn't connect to the server at $host:$port within $timeout seconds :-(<br>\nThe error I got was $errNo: $errStr";
        }
    

    Note that all this does is test whether the server is accepting connections on TCP:25565. It does not do anything to verify that the application listening on this port is actually the application you are looking for, or that it is functioning correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement a socket server that will run in most shared PHP
I'm trying to implement some kind of caching in a PHP script that will
I'm trying to implement a comment.php script that takes the data from a html
I'm implementing a PHP script which will need some caching capabilities. I'm trying to
I am currently trying to implement a job queue in php. The queue will
I am trying to implement a Javascript/PHP/AJAX clock into my website so that I
I'm developing a little web server in C++, now I'm trying to implement PHP
I'm trying to implement a PHP login script which works with 3 PHP files.
I'm trying to create a PHP logout script, however, as soon as I implement
I am trying to implement a php client that sends an HTTP GET to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.