Categories: Development

A method to check host name network status with PHP

This is a method to check if a host name is accessible i.e it is online, by using PHP. With fsocketopen() a connection will be created, if it fails false will be returned otherwise it will return a pointers.

In this script 192.168.0.1 gets pinged on port 80 the conditional statement will output simple statements based on the fsocketopen() response. Errors are suppressed with the @.

<?php
if (@fsockopen("192.168.0.1", 80) === false) {
   echo "Down";
} else {
   echo "Up";
}

If a connection was not rejected it will output Up otherwise the output will be Down.

Share

Recent Posts

Kennington reservoir drained drone images

A drained and empty Kennington reservoir images from a drone in early July 2024. The…

2 years ago

Merrimu Reservoir drone images

Merrimu Reservoir from drone. Click images to view larger.

2 years ago

Early September spring shots

Some early September spring shots from a bushwalk, It is still too early for wildflowers.

3 years ago

Cloning an NVMe to SK Hynix Platinum P41 NVMe

I recently needed to clone over a smaller NVMe to a 2TB SK Hynix Platinum…

3 years ago

Using Laravel’s deleteDirectory to delete folders and their contents

If you ever needed a simple solution in Laravel to delete an entire directory and…

3 years ago

How to allow only 1 user to register in a Laravel application

How to enforce only one user to register or be registered in a Laravel web…

3 years ago