Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
moodle-tool_opcache
2
===================
3
 
4
[![Moodle Plugin CI](https://github.com/moodle-an-hochschulen/moodle-tool_opcache/workflows/Moodle%20Plugin%20CI/badge.svg?branch=master)](https://github.com/moodle-an-hochschulen/moodle-tool_opcache/actions?query=workflow%3A%22Moodle+Plugin+CI%22+branch%3Amaster)
5
 
6
Moodle plugin which adds a PHP Opcache management GUI to Moodle site administration, a CLI tool to reset PHP Opcache and a Nagios check for PHP Opcache.
7
 
8
 
9
Requirements
10
------------
11
 
12
This plugin requires Moodle 4.3+
13
 
14
 
15
Motivation for this plugin
16
--------------------------
17
 
18
For performance reasons, Moodle should always be run with the Opcache PHP extension enabled. Unfortunately, PHP Opcache is kind of a black box and doesn't provide a management interface by default.
19
 
20
Luckily, there are some free Opcache management GUIs out there with Opcache-GUI by Andrew Collington (https://github.com/amnuts/opcache-gui) being the best-looking one. As a Moodle server administrator, you can just throw Opcache-GUI's single index.php file somewhere onto your Moodle server and get a Opcache management GUI instantly. However, this approach requires that you protect the Opcache-GUI from unauthorized access manually in your webserver and comes with the downside that Opcache-GUI is located outside Moodle.
21
 
22
For these reasons, we have packaged Opcache-GUI as a very simple Moodle admin tool providing it within Moodle site administration for Moodle administrators only.
23
 
24
As a companion feature to the Opcache-GUI which is used by Moodle administrators in the browser, we added a simple CLI tool to reset PHP Opcache from the command line.
25
 
26
Additionally as a companion feature to the Opcache-GUI which is used manually by Moodle administrators, we added a simple Nagios check for PHP Opcache which can be leveraged to monitor PHP Opcache usage automatically.
27
 
28
 
29
Installation
30
------------
31
 
32
Install the plugin like any other plugin to folder
33
/admin/tool/opcache
34
 
35
See http://docs.moodle.org/en/Installing_plugins for details on installing Moodle plugins
36
 
37
 
38
Usage
39
-----
40
 
41
After installing the plugin, it is active and fully working.
42
 
43
To use the plugin, please visit:
44
Site administration -> Server -> Opcache management.
45
 
46
Opcache-GUI should be self-explanatory for experienced PHP administrators.
47
For additional documentation about the usage of Opcache-GUI, please refer to the Opcache-GUI documentation on https://github.com/amnuts/opcache-gui/blob/master/README.md.
48
 
49
 
50
Capabilities
51
------------
52
 
53
This plugin does not add any additional capabilities.
54
 
55
 
56
How this plugin works
57
---------------------
58
 
59
This plugin works in a really simple way. It adds an admin tool page to Moodle's site administration tree and restricts access to this admin tool page to Moodle administrators (and other users having the moodle/site:config capability). Opcache-GUI is shipped as a library file with this plugin and is just included on the admin tool page.
60
 
61
 
62
Browser support
63
---------------
64
 
65
The Opcache-GUI which is used within this plugin is using ES6 Javascript code. In contrast to Moodle core, this JavaScript code is not transpiled to ES5 in any way. As a result, this plugin does not necessarily run in all legacy browsers which Moodle core still supports. However, this requirement just applies to the admin tool page on Site administration -> Server -> Opcache management, nothing more and nothing less.
66
 
67
 
68
Security note
69
-------------
70
 
71
The Opcache-GUI was added as a library to this Moodle plugin and was renamed to /lib/opcache-gui/index.php.inc.
72
 
73
There is a potential for sensitive data leak, not personal data but data about the webserver's PHP configuration, if your webserver is configured to interpret *.inc files as PHP. An anonymous user could then visit the library's index page directly via https://yourmoodle.com/admin/tool/opcache/lib/opcache-gui/index.php.inc and would see the Opcache-GUI circumventing Moodle's access control.
74
 
75
Please make sure that your webserver does not interpret *.inc files as PHP (which should be the default) or take any other measure that this file can not be accessed directly by a browser.
76
 
77
 
78
Privacy note
79
------------
80
 
81
The Opcache-GUI which is used within this plugin is using several JavaScript libraries from the unpkg.com CDN. This is important to note as Moodle core strives to be as CDN-free as possible normally. As a result, you will have to accept that your browser will fetch the JavaScript libraries from the CDN and during this request at least your IP address will be exposed to the CDN. However, this just applies to the admin tool page on Site administration -> Server -> Opcache management, nothing more and nothing less.
82
 
83
 
84
CLI tool
85
--------
86
 
87
The CLI tool for PHP Opcache is found in the cli subdirectory of the plugin directory. It consists of two parts:
88
 
89
### cli/reset_opcache_web.php
90
 
91
This file has to be run within the PHP webserver environment and is thus shipped within this plugin. Its only purpose is to reset PHP Opcache within the PHP webserver environment instead of the PHP CLI environment.
92
 
93
### cli/reset_opcache.php
94
 
95
This file is a Moodle CLI script which can only be run on the command line. To be able to reset PHP Opcache with reset_opcache_web.php, you have to provide the full URL to reset_opcache_web.php as parameter.
96
 
97
 
98
Security mechanism:
99
As cli/reset_opcache_web.php will reset PHP opcache without any Moodle user authentication and as this could be abused for denial-of-service attacks, a secret key has to be set in config.php. This secret key is used internally by cli/reset_opcache.php to call cli/reset_opcache_web.php. Without submitting the correct secret key to cli/reset_opcache_web.php, cli/reset_opcache_web.php will not reset PHP opcache.
100
 
101
To enable this CLI tool, please add this setting to your config.php file and set this setting to an alphanumeric string of your choice:
102
```
103
$CFG->tool_opcache_reset_secretkey = 'P3ethed8yCrAYfshzUTsGVKwedwfNZE89o3L6JZqHKMa';
104
```
105
 
106
 
107
Example usage:
108
```
109
sudo -u www-data /usr/bin/php admin/tool/cli/reset_opcache.php --url=\"https://example.com/admin/tool/opcache/cli/reset_opcache_web.php\" --reset
110
```
111
 
112
For more information about the usage run:
113
```
114
sudo -u www-data /usr/bin/php admin/tool/cli/reset_opcache.php --help
115
```
116
 
117
If run successfully, the CLI script will return a clear message:
118
```
119
PHP opcache has been reset successfully on this server.
120
```
121
 
122
If run unsuccessfully, the CLI script will also return an error message.
123
 
124
 
125
Nagios check
126
------------
127
 
128
The Nagios check for PHP Opcache is found in the cli subdirectory of the plugin directory. It consists of two parts:
129
 
130
### cli/check_opcache_web.php
131
 
132
This file has to be run within the PHP webserver environment and is thus shipped within this plugin. Its only purpose is to collect some basic figures of the current PHP Opcache usage and to return them one figure per line.
133
 
134
### cli/check_opcache.php
135
 
136
This file is a Moodle CLI script which can only be run on the command line. It is intended to be used by Nagios / NRPE or compatible monitoring solutions. To be able to fetch the basic figures provided by check_opcache_web.php, you have to provide the full URL to check_opcache_web.php as parameter.
137
 
138
 
139
Security mechanism:
140
As cli/clear_opcache_web.php will return some data about PHP opcache usage without any Moodle user authentication and as this might not be desired in all installations, a secret key can be set in config.php. If set, this secret key is used internally by cli/check_opcache.php to call cli/check_opcache_web.php. Without submitting the correct secret key to cli/check_opcache_web.php, cli/check_opcache_web.php will then not return any values.
141
 
142
To enable the security mechanism, please add this setting to your config.php file and set this setting to an alphanumeric string of your choice:
143
```
144
$CFG->tool_opcache_check_secretkey = 'P3ethed8yCrAYfshzUTsGVKwedwfNZE89o3L6JZqHKMa';
145
```
146
 
147
 
148
Example usage:
149
```
150
sudo -u www-data /usr/bin/php admin/tool/cli/check_opcache.php --url=\"https://example.com/admin/tool/opcache/cli/check_opcache_web.php\" --warning=80 --critical=90
151
```
152
 
153
For more information about the usage run:
154
```
155
sudo -u www-data /usr/bin/php admin/tool/cli/check_opcache.php --help
156
```
157
 
158
The CLI script will return a string similar to:
159
```
160
OK - 28.5% cache used | used_pct=28.5%;80;90 hit_pct=72.95%; miss_pct=27.05%;
161
```
162
 
163
 
164
Theme support
165
-------------
166
 
167
This plugin is developed and tested on Moodle Core's Boost theme.
168
It should also work with Boost child themes, including Moodle Core's Classic theme. However, we can't support any other theme than Boost.
169
 
170
 
171
Plugin repositories
172
-------------------
173
 
174
This plugin is published and regularly updated in the Moodle plugins repository:
175
http://moodle.org/plugins/view/tool_opcache
176
 
177
The latest development version can be found on Github:
178
https://github.com/moodle-an-hochschulen/moodle-tool_opcache
179
 
180
 
181
Bug and problem reports / Support requests
182
------------------------------------------
183
 
184
This plugin is carefully developed and thoroughly tested, but bugs and problems can always appear.
185
 
186
Please report bugs and problems on Github:
187
https://github.com/moodle-an-hochschulen/moodle-tool_opcache/issues
188
 
189
We will do our best to solve your problems, but please note that due to limited resources we can't always provide per-case support.
190
 
191
 
192
Feature proposals
193
-----------------
194
 
195
Due to limited resources, the functionality of this plugin is primarily implemented for our own local needs and published as-is to the community. We are aware that members of the community will have other needs and would love to see them solved by this plugin.
196
 
197
Please issue feature proposals on Github:
198
https://github.com/moodle-an-hochschulen/moodle-tool_opcache/issues
199
 
200
Please create pull requests on Github:
201
https://github.com/moodle-an-hochschulen/moodle-tool_opcache/pulls
202
 
203
We are always interested to read about your feature proposals or even get a pull request from you, but please accept that we can handle your issues only as feature _proposals_ and not as feature _requests_.
204
 
205
 
206
Moodle release support
207
----------------------
208
 
209
Due to limited resources, this plugin is only maintained for the most recent major release of Moodle as well as the most recent LTS release of Moodle. Bugfixes are backported to the LTS release. However, new features and improvements are not necessarily backported to the LTS release.
210
 
211
Apart from these maintained releases, previous versions of this plugin which work in legacy major releases of Moodle are still available as-is without any further updates in the Moodle Plugins repository.
212
 
213
There may be several weeks after a new major release of Moodle has been published until we can do a compatibility check and fix problems if necessary. If you encounter problems with a new major release of Moodle - or can confirm that this plugin still works with a new major release - please let us know on Github.
214
 
215
If you are running a legacy version of Moodle, but want or need to run the latest version of this plugin, you can get the latest version of the plugin, remove the line starting with $plugin->requires from version.php and use this latest plugin version then on your legacy Moodle. However, please note that you will run this setup completely at your own risk. We can't support this approach in any way and there is an undeniable risk for erratic behavior.
216
 
217
 
218
Translating this plugin
219
-----------------------
220
 
221
This Moodle plugin is shipped with an english language pack only. All translations into other languages must be managed through AMOS (https://lang.moodle.org) by what they will become part of Moodle's official language pack.
222
 
223
As the plugin creator, we manage the translation into german for our own local needs on AMOS. Please contribute your translation into all other languages in AMOS where they will be reviewed by the official language pack maintainers for Moodle.
224
 
225
 
226
Right-to-left support
227
---------------------
228
 
229
This plugin has not been tested with Moodle's support for right-to-left (RTL) languages.
230
If you want to use this plugin with a RTL language and it doesn't work as-is, you are free to send us a pull request on Github with modifications.
231
 
232
 
233
Maintainers
234
-----------
235
 
236
The plugin is maintained by\
237
Moodle an Hochschulen e.V.
238
 
239
 
240
Copyright
241
---------
242
 
243
The copyright of this plugin is held by\
244
Moodle an Hochschulen e.V.
245
 
246
Individual copyrights of individual developers are tracked in PHPDoc comments and Git commits.
247
 
248
 
249
Initial copyright
250
-----------------
251
 
252
This plugin was initially built, maintained and published by\
253
Ulm University\
254
Communication and Information Centre (kiz)\
255
Alexander Bias
256
 
257
It was contributed to the Moodle an Hochschulen e.V. plugin catalogue in 2022.
258
 
259
 
260
Credits
261
-------
262
 
263
This Moodle plugin is only a simple wrapper for Opcache-GUI by Andrew Collington.
264
Andrew owns all copyrights for Opcache-GUI and maintains this tool on https://github.com/amnuts/opcache-gui.
265
 
266
The Nagios check in this plugin was inspired by code by Mikanoshi which is published on https://exchange.icinga.com/Mikanoshi/PHP+opcache+monitoring+plugin.