PHP code example of phpbg / rtsp

1. Go to this page and download the library: Download phpbg/rtsp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phpbg / rtsp example snippets




$loop = React\EventLoop\Factory::create();

//Normal port is 554 but we use 5540 instead to avoid root nction (\PhpBg\Rtsp\Message\Request $request, \React\Socket\ConnectionInterface $connection) {
    echo $request;
    $response = \PhpBg\Rtsp\Message\MessageFactory::response();
    $response->setHeader('cseq', $request->getHeader('cseq'));
    return $response;
});

$server->on('error', function (\Exception $e) {
    echo $e->getMessage() . "\r\n";
    echo $e->getTraceAsString() . "\r\n";
});

$server->listen($socket);
echo "Server started\r\n";
echo "Open any decent video player (e.g. vlc, mpv) and open rtsp://localhost:5540\r\n";
$loop->run();



$loop = React\EventLoop\Factory::create();

//Normal port is 554 but we use 5540 instead to avoid root p\Middleware\Log(),
    new \PhpBg\Rtsp\Middleware\AutoCseq(),
    new \PhpBg\Rtsp\Middleware\AutoContentLength(),
    function (\PhpBg\Rtsp\Message\Request $request, \React\Socket\ConnectionInterface $connection) {
        // 200 OK response middleware
        return \PhpBg\Rtsp\Message\MessageFactory::response();
    }
];

$server = new \PhpBg\Rtsp\Server(new \PhpBg\Rtsp\Middleware\MiddlewareStack($middlewares));

$server->on('error', function (\Exception $e) {
    echo $e->getMessage() . "\r\n";
    echo $e->getTraceAsString() . "\r\n";
});

$server->listen($socket);
echo "Server started\r\n";
echo "Open any decent video player (e.g. vlc, mpv) and open rtsp://localhost:5540\r\n";
$loop->run();