You can open a socket connection inside of php. Using @fsockopen function. This is simple code so i will show you a example.

<?php
//ip address of you server
$ip = "127.0.0.1";
//port of your minecraft server
$port = 25565;

// create a connection using the fsockopen function

$coonectionStream = @fsockopen( $ip, $port, $errno, $errstr, 2);

//check if the connection worked and the server is online

if($coonectionStream >= 1) {
    echo 'MineCraft server is online';
    //echo out information if server is online
} else {
    echo 'MineCraft server is offline';
    //echo out information if server is offline
}
?>

Just one note the last parameter to be passed to the fsockopen function is the connection time out this is the length of time that the fsockopen function will try and connect to the socket over the given ip. Why this is important is because this holds up the server from returning any information to the page. So if you have 2 seconds there it will try and connect for 2 seconds before returning any information. Not a big deal but if you increase the time then people may not wait for you page to load because it is just taking to long for it to fail and say there server is offline.

I hope this helps!

For more information on the fsockopen function go here.

If anyone has any questions or would like information about any other subject involving  PHP, JavaScript, Jquery, or CSS please leave a comment and I’ll write a post about it.