-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcron.php
70 lines (51 loc) · 2.32 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
<?PHP
/*========================================================================================*\
# Coder : Ian Newton
# Date : 24th May,2011
# Test version
# controller to process actions queued in the media_actions table and report status to the admin server
\*=========================================================================================*/
// Initialise objects
$mysqli = new mysqli($dbLogin['dbhost'], $dbLogin['dbusername'], $dbLogin['dbuserpass'], $dbLogin['dbname']);
$outObj = new Default_Model_Output_Class($mysqli);
$dataObj = new Default_Model_Action_Class($mysqli,$outObj);
$apCommand="curl -d \"number=5&time=2\" ".$destination['admin-api']."/poll.php";
// Check and/or start 2s polling process
$dataObj->startCheckProcess($apCommand);
// Clean up old processes and api-log
$mysqli->query(" DELETE FROM `api_process`
WHERE ap_timestamp < (now() - interval 5 minute)
AND `ap_status`='N' ");
$mysqli->query(" DELETE FROM `api_log`
WHERE al_timestamp < (now() - interval 12 hour)");
// - Proccessing of commands part -----------------------------------------------------------------------------------------
// Get the actions from the queue table
$timeStart= time();
// Loop every 3 seconds if we can
while ( time() < $timeStart + 8 ) {
$result1 = $mysqli->query(" SELECT mq.mq_index, mq.mq_status
FROM queue_messages AS mq
WHERE mq.mq_status IN('N')
ORDER BY mq.mq_time_start");
if (isset($result1->num_rows)) {
// Process the outstanding commands for each message
$cqCommand="'queue','direct'";
while( $row1 = $result1->fetch_object()) {
// $debug[] = $row1;
if ($row1->mq_status=='N') $m_data = $dataObj->doNextAction($row1->mq_index, $cqCommand);
$reply[] = $dataObj->doMessageCompletion($row1->mq_index);
}
}
// - Proccessing callbacks part -----------------------------------------------------------------------------------------
$dataObj->doCallback();
ob_clean();
sleep(3);
}
// Clean up old completed commands
$mysqli->query(" DELETE FROM `queue_commands`
WHERE cq_time < (now() - interval 12 hour)
AND `cq_status`='C' ");
$mysqli->query(" DELETE FROM `queue_messages`
WHERE mq_time_start < (now() - interval 12 hour)
AND `mq_status`='C' ");
?>