How can fsockopen be used to check if a webcam server is running in PHP?

To check if a webcam server is running in PHP, you can use the fsockopen function to establish a connection to the server. If the connection is successful, it means the server is running. You can check for a specific port that the webcam server is running on, such as port 80 for HTTP or port 554 for RTSP.

$server = 'webcamserver.com';
$port = 80;

$socket = @fsockopen($server, $port, $errno, $errstr, 1);

if ($socket) {
    echo 'Webcam server is running';
    fclose($socket);
} else {
    echo 'Webcam server is not running';
}