-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
64 lines (35 loc) · 1.17 KB
/
index.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
<?php
class Afterhours {
private $_enabled = false;
private $_jobs = array();
private $_functions = array();
public __construct() {
$apiName = php_sapi_name();
if (substr($apiName, 0, 3) === 'cgi' && function_exists('fastcgi_finish_request'))
$this->_enabled = true;
}
public function addJob(string $functionName, array $args = array()) {
$this->_jobs[] = array(
'function' => $functionName,
'args' => $args
);
}
public function addFunction($name, $function) {
if (!isset($this->_functions[$name]) && is_callable($function)) {
$this->_functions[$name] = $function;
return true;
}
return false;
}
public function runJobs($force = false) {
if ($this->_enabled || $force) {
if (function_exists('fastcgi_finish_request'))
fastcgi_finish_request();
foreach ($this->_jobs as $job) {
$function = $this->_functions[$job['function']];
$args = $job['args'];
call_user_func_array($function, $args);
}
}
}
}