I am running a couple of live and vod streams being segmented with ffmpeg. I run one channel per cloud server. I have a central, more robust server which i use for various tasks one of those task being ingesting the main m3u8 playlist and storing the segment names and creation times in a database.
The segments are created about every 8 seconds currently for 8 channels. This means that every 8 seconds i call the playlist.m3u8 (which is on a remote server) and store the information for each segment in the database.
This allows me to quickly create the vod (Select from channel 1 between time and time).
However, once or twice the database seems to have stopped working and I need to repair it before it can take new information.
I am wondering, am I hitting it too hard? Is there a better way?
My statement opens a new connection, checks if the entry already exists, if not it will enter it, then it closes the connection.
I do this once per channel per 8 seconds.
This feels like it could be better but I don't quite know how. Should I / can I keep the connection open maybe? Maybe its not a problem at all.
Anyone have any advice?
If you need more information just ask.
Query:
$conn = new mysqli($servername, $username, $password, $dbname);
$eight = date('Y-m-d', strtotime("-8 day"));
$vq = "SELECT * FROM `".$channels['channels'][$id]['fo_id']."`
WHERE `segment_name` = '".$oline."'";
$query = mysqli_query($conn, $vq);
if(mysqli_num_rows($query) == 0){
$sql = "INSERT INTO `".$channels['channels'][$id]['fo_id']."`
(`segment_name`, `server`, `created`, `lenght`)
VALUES
('".$oline."', '".$channels['channels'][$id]['server']."',
'".date("Y-m-d H:i:s", $date)."', '".$otime."')";
$conn->query($sql);
}
$query = mysqli_query($conn, "DELETE FROM `".$channels['channels'][$id]['fo_id']."`
WHERE `created` < '".$eight." 00:00:00'");
$conn->close();