-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathserver.php
54 lines (44 loc) · 1.58 KB
/
server.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
<?php
include ('vendor/autoload.php');
use prodigyview\media\Video;
use prodigyview\util\FileManager;
use PhpAmqpLib\Connection\AMQPStreamConnection;
//Start RabbitMQ Server
$connection = new AMQPStreamConnection('rabbitmq', 5672, 'guest', 'guest');
$channel = $connection->channel();
$channel->queue_declare('video_queue', //$queue - Either sets the queue or creates it if not exist
false, //$passive - Do not modify the servers state
true, //$durable - Data will persist if crash or restart occurs
false, //$exclusive - Only one connection will usee, and deleted when closed
false //$auto_delete - Queue is deleted when consumer is no longer subscribes
);
/**
* Define the callback function
*/
$callback = function($msg) {
//Convert the data to array
$data = json_decode($msg->body, true);
//Detect if wget and ffmpeg are installed
exec("command -v wget", $wget_exist);
exec("command -v ffmpeg", $ffmpeg_exist);
if ($wget_exist) {
//Use wget to download the video.
exec("wget -O video.mp4 {$data['video_url']}");
} else {
//Use ProdigyView's FileManager as backup
FileManager::copyFileFromUrl($data['video_url'], getcwd() . '/', 'video.mp4');
}
if ($ffmpeg_exist) {
//Run a conversion using ffmpeg
Video::convertVideoFile('video.mp4', 'video.' . $data['convert_to']);
} else {
echo "Sorry No Conversion Software Exist On Server\n";
}
echo "Finished Processing\n";
};
//Pass the callback
$channel->basic_consume('video_queue', '', false, false, false, false, $callback);
//Listen to requests
while (count($channel->callbacks)) {
$channel->wait();
}