Create stream_control.php

This commit is contained in:
2025-09-21 19:26:27 +02:00
committed by GitHub
parent 1d50147c75
commit 7111ca10b5
+33
View File
@@ -0,0 +1,33 @@
<?php
session_start();
function startEncoder() {
exec('nohup /var/www/html/stream_konvertieren.sh > /dev/null 2>&1 & echo $!', $output);
return $output[0];
}
function stopEncoder($pid) {
exec("kill $pid");
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$action = $_POST['action'];
if ($action === 'start') {
if (!isset($_SESSION['encoder_pid'])) {
$pid = startEncoder();
$_SESSION['encoder_pid'] = $pid;
echo json_encode(['status' => 'started', 'pid' => $pid]);
} else {
echo json_encode(['status' => 'already_running', 'pid' => $_SESSION['encoder_pid']]);
}
} elseif ($action === 'stop') {
if (isset($_SESSION['encoder_pid'])) {
stopEncoder($_SESSION['encoder_pid']);
unset($_SESSION['encoder_pid']);
echo json_encode(['status' => 'stopped']);
} else {
echo json_encode(['status' => 'not_running']);
}
}
}