-
Notifications
You must be signed in to change notification settings - Fork 19
/
cron.php
88 lines (84 loc) · 4.34 KB
/
cron.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
if (isset($_SERVER['SERVER_ADDR'])) {
if ($_SERVER['REMOTE_ADDR'] != $_SERVER['SERVER_ADDR']) {
die('access is not permitted');
}
}
include('config.php');
$setting = Setting::first();
foreach (Stream::where('pid', '!=', 0)->where('running', '=', 1)->get() as $stream) {
if (!checkPid($stream->pid)) {
$stream->checker = 0;
$checkstreamurl = shell_exec('/usr/bin/timeout 15s ' . $setting->ffprobe_path . ' -analyzeduration 10000000 -probesize 9000000 -i "' . $stream->streamurl . '" -v quiet -print_format json -show_streams 2>&1');
$streaminfo = (array)json_decode($checkstreamurl);
if (count($streaminfo) > 0) {
$pid = shell_exec(getTranscode($stream->id));
$stream->pid = $pid;
$stream->running = 1;
$stream->status = 1;
} else {
$stream->running = 1;
$stream->status = 2;
shell_exec("kill -9 " . $stream->pid);
shell_exec("/bin/rm -r /home/fos-streaming/fos/www/" . $setting->hlsfolder . "/" . $stream->id . "*");
if ($stream->streamurl2) {
$stream->checker = 2;
echo "checking stream 2";
$checkstreamurl = shell_exec('/usr/bin/timeout 15s ' . $setting->ffprobe_path . ' -analyzeduration 10000000 -probesize 9000000 -i "' . $stream->streamurl2 . '" -v quiet -print_format json -show_streams 2>&1');
$streaminfo = (array)json_decode($checkstreamurl);
if (count($streaminfo) > 0) {
echo getTranscode($stream->id, 2);
$pid = shell_exec(getTranscode($stream->id, 2));
$stream->pid = $pid;
$stream->running = 1;
$stream->status = 1;
} else {
$stream->running = 1;
$stream->status = 2;
shell_exec("kill -9 " . $stream->pid);
shell_exec("/bin/rm -r /home/fos-streaming/fos/www/" . $setting->hlsfolder . "/" . $stream->id . "*");
if ($stream->streamurl3) {
$stream->checker = 3;
$checkstreamurl = shell_exec('/usr/bin/timeout 15s ' . $setting->ffprobe_path . ' -analyzeduration 10000000 -probesize 9000000 -i "' . $stream->streamurl3 . '" -v quiet -print_format json -show_streams 2>&1');
$streaminfo = (array)json_decode($checkstreamurl);
if (count($streaminfo) > 0) {
$pid = shell_exec(getTranscode($stream->id, 3));
$stream->pid = $pid;
$stream->running = 1;
$stream->status = 1;
} else {
$stream->running = 1;
$stream->status = 2;
}
}
}
}
}
$stream->save();
}
}
foreach (Stream::where('restream', '=', 1)->where('running', '=', 1)->get() as $stream) {
$stream->checker = 0;
$checkstreamurl = shell_exec('/usr/bin/timeout 15s ' . $setting->ffprobe_path . ' -analyzeduration 10000000 -probesize 9000000 -i "' . $stream->streamurl . '" -v quiet -print_format json -show_streams 2>&1');
$streaminfo = (array)json_decode($checkstreamurl);
if (count($streaminfo) > 0) {
$stream->checker = 0;
} else {
if ($stream->streamurl2) {
$checkstreamurl = shell_exec('/usr/bin/timeout 15s ' . $setting->ffprobe_path . ' -analyzeduration 10000000 -probesize 9000000 -i "' . $stream->streamurl2 . '" -v quiet -print_format json -show_streams 2>&1');
$streaminfo = (array)json_decode($checkstreamurl);
if (count($streaminfo) > 0) {
$stream->checker = 2;
} else { // fail 2
if ($stream->streamurl3) {
$checkstreamurl = shell_exec('/usr/bin/timeout 15s ' . $setting->ffprobe_path . ' -analyzeduration 10000000 -probesize 9000000 -i "' . $stream->streamurl3 . '" -v quiet -print_format json -show_streams 2>&1');
$streaminfo = (array)json_decode($checkstreamurl);
if (count($streaminfo) > 0) {
$stream->checker = 3;
}
}
}
}
}
$stream->save();
}