-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoffLogWorker.php
110 lines (91 loc) · 2.21 KB
/
offLogWorker.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/**
* OffLog - worker
*
* The back end worker that takes the logging tasks from Gearman
* and puts them in the correct memecache slice (ring buffer)
*
* PHP version 5
*
* LICENSE: MIT License
*
* @category Reporting
* @package Reporting
* @link http://www.metalcat.net/offlog/
* @author Jeremy Hutchings <email@jeremyhutchings.com>
* @license http://en.wikipedia.org/wiki/MIT_License
*
*/
/**
* Get the config data
*/
include 'config/sharedconfig.php';
/**
* Connect to the memcache ring buffer
*
* @var object Memcache
*/
$memcache = null;
if (!$memcache = new Memcache($offLogCfg['memcache']['ip'], $offLogCfg['memcache']['port']))
{
die (date("F j, Y, g:i a") . " Coudn't connect to Memcache");
}
else
{
echo date("F j, Y, g:i a") . " Connected to Memcache\n";
}
/**
* The gearman worker instance
*
* @var unknown_type
*/
$worker= new GearmanWorker();
/**
* Add the default server, don't use config as worker is run locally
* to gearman server atm, so no config defaults to localhost
*/
if (!$worker->addServer() OR !$worker->echo("ping"))
{
die (date("F j, Y, g:i a") ." Can't connect to gearman server\n");
}
else
{
echo date("F j, Y, g:i a") . " Connected to Gearman Server\n";
}
/**
* Add the logging functions
*/
if (!$worker->addFunction("logSimple", "logSimple_cd"))
{
die (date("F j, Y, g:i a") . "Couldn't add function :: logSimple");
}
else
{
echo date("F j, Y, g:i a") . " Function added :: logSimple\n";
}
/**
* All set up, now start the worker
*/
while ($worker->work());
# ---------------------------------------------------------------------------
# Logging functions
# ---------------------------------------------------------------------------
function logSimple_cd($job)
{
// Get the slice from the time, 0-5
$slice = substr(date('i'), 0, 1);
// Get the log details
$bits = json_decode($job->workload());
// $get the
// Make sure the action is in the register
var_dump($bits);
return 1;
}
function memcache_safeadd(&$memcache_obj, $key, $value, $flag, $expire)
{
if (memcache_add($memcache_obj, $key, $value, $flag, $expire))
{
return ($value == memcache_get($memcache_obj, $key));
}
return FALSE;
}