1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
Plugin Name: VroomPlugin |
4
|
|
|
Plugin URI: http://mitre.org/ |
5
|
|
|
Description: Vroom speeds up elgg |
6
|
|
|
Version: 1.0 |
7
|
|
|
Author: Michael Jett |
8
|
|
|
Author URI: http://www.mitre.org/ |
9
|
|
|
Author Email: [email protected] |
10
|
|
|
License: |
11
|
|
|
|
12
|
|
|
Copyright 2013 MITRE ([email protected]) |
13
|
|
|
|
14
|
|
|
This program is free software; you can redistribute it and/or modify |
15
|
|
|
it under the terms of the GNU General Public License, version 2, as |
16
|
|
|
published by the Free Software Foundation. |
17
|
|
|
|
18
|
|
|
This program is distributed in the hope that it will be useful, |
19
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
20
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21
|
|
|
GNU General Public License for more details. |
22
|
|
|
|
23
|
|
|
You should have received a copy of the GNU General Public License |
24
|
|
|
along with this program; if not, write to the Free Software |
25
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
26
|
|
|
|
27
|
|
|
*/ |
28
|
|
|
class VroomPlugin |
29
|
|
|
{ |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Class construct |
33
|
|
|
*/ |
34
|
|
|
public function __construct() |
35
|
|
|
{ |
36
|
|
|
// Initialize hooks |
37
|
|
|
elgg_register_event_handler('init', 'system', array($this, 'init')); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Called when the elgg system initializes |
42
|
|
|
*/ |
43
|
|
|
public function init() |
44
|
|
|
{ |
45
|
|
|
/* |
46
|
|
|
* After elgg finishes an entire system execution, send the output to browser |
47
|
|
|
* This allows the other system shutdown processes to continue in the background while output gets returned to the user promptly |
48
|
|
|
*/ |
49
|
|
|
elgg_register_event_handler('shutdown', 'system', array($this, 'flushToBrowser'), 0); |
|
|
|
|
50
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Forces output to the browser so additional php functionality can continue in the background |
55
|
|
|
*/ |
56
|
|
|
public function flushToBrowser() |
57
|
|
|
{ |
58
|
|
|
// Registering a shutdown flag allows other points in jettmail to determine if the state is in shutdown |
59
|
|
|
$GLOBALS['shutdown_flag'] = 1; |
60
|
|
|
|
61
|
|
|
// Check to see if the headers have been sent or another plugin is sending a different connection header |
62
|
|
|
if (!headers_sent() && !self::connectionSent()) { |
63
|
|
|
|
64
|
|
|
// Ignore user aborts and allow the script to run forever |
65
|
|
|
ignore_user_abort(true); |
66
|
|
|
session_write_close(); |
67
|
|
|
set_time_limit(0); |
68
|
|
|
|
69
|
|
|
// Tell the browser that we are done |
70
|
|
|
header("Connection: close"); |
71
|
|
|
$size = ob_get_length(); |
72
|
|
|
header("Content-Length: $size"); |
73
|
|
|
ob_end_flush(); |
74
|
|
|
|
75
|
|
|
// allow vroom for fastcgi instances |
76
|
|
|
if (is_callable('fastcgi_finish_request')) { |
77
|
|
|
fastcgi_finish_request(); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
flush(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Sifts through the headers to see if a connection has been sent |
87
|
|
|
* |
88
|
|
|
* This is useful if a plugin wants to keep a connection alive |
89
|
|
|
* @return bool |
90
|
|
|
*/ |
91
|
|
|
public function connectionSent () { |
92
|
|
|
|
93
|
|
|
$headers = headers_list(); |
94
|
|
|
|
95
|
|
|
foreach ($headers as $hdr) { |
96
|
|
|
if (stripos($hdr, "Connection") === 0) { |
97
|
|
|
return true; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
return false; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: