-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmsqueue.php
85 lines (64 loc) · 2.18 KB
/
smsqueue.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
<?php
require_once 'vendor/autoload.php';
use Predis\Client;
use AndrewBreksa\RSMQ\RSMQClient;
$predis = new Client([
'host' => 'redis',
'port' => 6379
]);
$rsmq = new RSMQClient($predis);
// for create queue
try{
$rsmq->createQueue('myqueue');
}catch(Exception $e){
}
function insertQueue($message, $rsmq, $messageResponse){
$id = $rsmq->sendMessage('myqueue', $message);
header('Location:index.php?messageResponse='.$messageResponse);
}
function retrieve($rsmq){
$message = $rsmq->popMessage('myqueue');
if(!empty($message)){
$rs['FIFO'] = [
'id' => $message->getId(),
'message' => $message->getMessage(),
];
}else{
$rs = ['message' => 'Queue have been cleared !'];
}
header("Content-Type: application/json");
echo json_encode($rs);
}
function total($rsmq){
$attributes = $rsmq->getQueueAttributes('myqueue');
$rs = ['Current No of Messages in Queue' => $attributes->getMessageCount()];
header("Content-Type: application/json");
echo json_encode($rs);
}
function all($rsmq){
$message['All Message in queue'] = $rsmq->displayMessage('myqueue');
header("Content-Type: application/json");
echo json_encode($message);
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if(isset($_GET['retrieve'])){
retrieve($rsmq);
}elseif(isset($_GET['total'])){
total($rsmq);
}elseif(isset($_GET['all'])){
all($rsmq);
}else{
if(empty($_POST["message"])) {
$messageResponse = '<span class="error">* SMS Message is required !</span>';
header('Location:index.php?messageResponse='.$messageResponse);
}else{
$message = test_input($_POST["message"]);
$messageResponse = '<span class="success">* SMS Message succesfully been queued</span>';
insertQueue($message, $rsmq, $messageResponse);
}
}