PluginProbe
Docket Cache – Object Cache Accelerator / 24.07.07
Docket Cache – Object Cache Accelerator v24.07.07
26.04.05 trunk 22.07.01 22.07.02 22.07.03 22.07.04 22.07.05 23.08.01 23.08.02 24.07.01 24.07.02 24.07.03 24.07.04 24.07.05 24.07.06 24.07.07 26.04.03 26.04.04
docket-cache / includes / src / Constans.php

Constans.php in Docket Cache – Object Cache Accelerator 24.07.07, at includes/src/Constans.php

563 lines 17.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Docket Cache.
4 *
5 * @author Nawawi Jamili
6 * @license MIT
7 *
8 * @see https://github.com/nawawi/docket-cache
9 */
10
11 namespace Nawawi\DocketCache;
12
13 \defined('ABSPATH') || exit;
14
15 final class Constans
16 {
17 public function __construct()
18 {
19 $this->register_default();
20 }
21
22 public function px($name)
23 {
24 return nwdcx_constfx($name);
25 }
26
27 public function is_false($name)
28 {
29 return !\defined($name) || !\constant($name);
30 }
31
32 public function is_true($name)
33 {
34 return \defined($name) && \constant($name);
35 }
36
37 public function value($name)
38 {
39 $value = '';
40 if (\defined($name)) {
41 $value = \constant($name);
42 }
43
44 return $value;
45 }
46
47 public function is_array($name)
48 {
49 $value = $this->value($name);
50
51 return !empty($value) && \is_array($value);
52 }
53
54 public function is_int($name)
55 {
56 $value = $this->value($name);
57
58 return !empty($value) && \is_int($value);
59 }
60
61 public function is($name, $value)
62 {
63 return \defined($name) && $value === \constant($name);
64 }
65
66 public function is_dctrue($name, $reload = false)
67 {
68 $key = $this->px($name);
69 if ($reload) {
70 $this->maybe_define($key, false, true);
71 }
72
73 return $this->is_true($key);
74 }
75
76 public function is_dcfalse($name, $reload = false)
77 {
78 $key = $this->px($name);
79 if ($reload) {
80 $this->maybe_define($key, false, true);
81 }
82
83 return $this->is_false($key);
84 }
85
86 public function is_dcarray($name, &$value = '', $reload = false)
87 {
88 $key = $this->px($name);
89 if ($reload) {
90 $this->maybe_define($key, false, true);
91 }
92
93 $value = '';
94 if ($this->is_array($key)) {
95 $value = $this->value($key);
96
97 return true;
98 }
99
100 return false;
101 }
102
103 public function is_dcint($name, &$value = '', $reload = false)
104 {
105 $key = $this->px($name);
106 if ($reload) {
107 $this->maybe_define($key, false, true);
108 }
109
110 $value = '';
111 if ($this->is_int($key)) {
112 $value = $this->value($key);
113
114 return true;
115 }
116
117 return false;
118 }
119
120 public function dcvalue($name, $reload = false)
121 {
122 $key = $this->px($name);
123 if ($reload) {
124 $this->maybe_define($key, '', true);
125 }
126
127 return $this->value($key);
128 }
129
130 public function maybe_define($name, $value, $user_config = true)
131 {
132 if (!\defined($name)) {
133 if ($user_config && class_exists('Nawawi\\DocketCache\\Canopt')) {
134 $nv = Canopt::init()->get($name);
135 if (!empty($nv) && 'default' !== $nv) {
136 switch ($nv) {
137 case 'enable':
138 $nv = true;
139 break;
140 case 'disable':
141 $nv = false;
142 break;
143 }
144
145 $value = $nv;
146 }
147 }
148
149 return @\define($name, $value);
150 }
151
152 // mark defined constants
153 if (empty($GLOBALS['DOCKET_CACHE_RUNTIME'])) {
154 $GLOBALS['DOCKET_CACHE_RUNTIME'] = [];
155 }
156 $GLOBAL['DOCKET_CACHE_RUNTIME'][$this->px($name.'_FALSE')] = 1;
157
158 return false;
159 }
160
161 public function register_default()
162 {
163 // compat
164 $this->maybe_define('WP_CONTENT_DIR', nwdcx_normalizepath(ABSPATH).'wp-content', false);
165 $this->maybe_define('WP_PLUGIN_DIR', nwdcx_normalizepath(WP_CONTENT_DIR).'/plugins', false);
166 $this->maybe_define('DOCKET_CACHE_CONTENT_PATH', nwdcx_normalizepath(WP_CONTENT_DIR), false);
167
168 // data dir
169 $this->maybe_define($this->px('DATA_PATH'), DOCKET_CACHE_CONTENT_PATH.'/docket-cache-data/', false);
170
171 // cache dir
172 $this->maybe_define($this->px('PATH'), DOCKET_CACHE_CONTENT_PATH.'/cache/docket-cache/', false);
173
174 // object max size: 3MB, 1MB = 1048576 bytes (binary) = 1000000 bytes (decimal)
175 // Only numbers between 1000000 and 10485760 are accepted
176 $this->maybe_define($this->px('MAXSIZE'), 3145728);
177
178 // cache file max size total: 500MB, 1MB = 1048576 bytes (binary) = 1000000 bytes (decimal)
179 // minimum 100MB
180 $this->maybe_define($this->px('MAXSIZE_DISK'), 524288000);
181
182 // cache file max accelerated files: Only numbers between 200 and 200000 are accepted
183 $this->maybe_define($this->px('MAXFILE'), 50000);
184
185 // check cache file limit in real-time
186 $this->maybe_define($this->px('MAXFILE_LIVECHECK'), false);
187
188 // cache maxttl: cache lifespan. Only seconds between 86400 and 2419200 are accepted
189 $this->maybe_define($this->px('MAXTTL'), 345600); // 4d
190
191 // log on/off
192 $this->maybe_define($this->px('LOG'), false);
193
194 // log all on/off
195 $this->maybe_define($this->px('LOG_ALL'), \defined('WP_DEBUG') ? WP_DEBUG : false);
196
197 // log file
198 $this->maybe_define($this->px('LOG_FILE'), DOCKET_CACHE_CONTENT_PATH.'/.object-cache.log');
199
200 // empty file when cache flushed
201 $this->maybe_define($this->px('LOG_FLUSH'), true);
202
203 // log time format: utc, local
204 $this->maybe_define($this->px('LOG_TIME'), 'utc');
205
206 // log file max size: 10MB, 1MB = 1048576 bytes (binary) = 1000000 bytes (decimal)
207 $this->maybe_define($this->px('LOG_SIZE'), 10485760);
208
209 // truncate or delete cache file
210 $this->maybe_define($this->px('FLUSH_DELETE'), false);
211
212 // flush cache when deactivate/uninstall
213 $this->maybe_define($this->px('FLUSH_SHUTDOWN'), true);
214
215 // flush wc_cache / advanced post cache / wp stale cache
216 $this->maybe_define($this->px('FLUSH_STALECACHE'), false);
217
218 // split a cache file into smaller directory
219 $this->maybe_define($this->px('CHUNKCACHEDIR'), false);
220
221 // ignore stale cache
222 $this->maybe_define($this->px('STALECACHE_IGNORE'), false);
223
224 // ignore empty cache
225 $this->maybe_define($this->px('EMPTYCACHE_IGNORE'), false);
226
227 // optimize db
228 $this->maybe_define($this->px('CRONOPTMZDB'), 'never');
229
230 // option autoload
231 $this->maybe_define($this->px('WPOPTALOAD'), false);
232
233 // global cache group for multisite
234 $this->maybe_define(
235 $this->px('GLOBAL_GROUPS'),
236 [
237 'blog-details',
238 'blog-id-cache',
239 'blog-lookup',
240 'global-posts',
241 'networks',
242 'network-queries',
243 'rss',
244 'sites',
245 'site-details',
246 'site-lookup',
247 'site-options',
248 'site-queries',
249 'site-transient',
250 'users',
251 'useremail',
252 'userlogins',
253 'usermeta',
254 'user_meta',
255 'userslugs',
256 ]
257 );
258
259 // cache ignored groups
260 $this->maybe_define(
261 $this->px('IGNORED_GROUPS'),
262 [
263 'themes',
264 'counts',
265 'plugins',
266 ]
267 );
268
269 // @private
270 // cache ignored keys
271 // @note: dnh_dismissed_notices -> https://github.com/julien731/WP-Dismissible-Notices-Handler
272 $this->maybe_define($this->px('IGNORED_KEYS'), ['dnh_dismissed_notices']);
273
274 // @private
275 // cache ignored group => key, group => [key1, key2]
276 $this->maybe_define($this->px('IGNORED_GROUPKEY'), []);
277
278 // @private
279 // this option private for right now
280 $this->maybe_define(
281 $this->px('FILTERED_GROUPS'),
282 [
283 'counts' => [
284 'posts-page',
285 'posts-post',
286 ],
287 ]
288 );
289
290 // precache
291 $this->maybe_define($this->px('PRECACHE'), false);
292
293 // precache maxfile
294 $this->maybe_define($this->px('PRECACHE_MAXFILE'), 100);
295
296 // precache max key
297 $this->maybe_define($this->px('PRECACHE_MAXKEY'), 20);
298
299 // precache max group
300 $this->maybe_define($this->px('PRECACHE_MAXGROUP'), 20);
301
302 // @private
303 // cache ignored precache
304 $this->maybe_define(
305 $this->px('IGNORED_PRECACHE'),
306 [
307 'freemius' => 'fs_accounts',
308 'options' => [
309 'uninstall_plugins',
310 'auto_update_plugins',
311 'active_plugins',
312 'cron',
313 'litespeed_messages',
314 'litespeed.admin_display.messages',
315 ],
316 'site-options' => [
317 '1:auto_update_plugins',
318 '1:active_sitewide_plugins',
319 ],
320 ]
321 );
322
323 // transient in DB.
324 $this->maybe_define($this->px('TRANSIENTDB'), false);
325
326 // exclude transient in DB.
327 $this->maybe_define($this->px('IGNORED_TRANSIENTDB'),
328 [
329 'doing_cron',
330 'update_plugins',
331 'update_themes',
332 'update_core',
333 ]
334 );
335
336 // misc tweaks
337 $this->maybe_define($this->px('MISC_TWEAKS'), true);
338
339 // woocommerce tweaks
340 $this->maybe_define($this->px('WOOTWEAKS'), true);
341
342 // woocommerce admin
343 $this->maybe_define($this->px('WOOADMINOFF'), false);
344
345 // woocommerce dashboard status meta box
346 $this->maybe_define($this->px('WOOWPDASHBOARDOFF'), false);
347
348 // woocommerce widget
349 $this->maybe_define($this->px('WOOWIDGETOFF'), false);
350
351 // woocommerce cart fragments
352 $this->maybe_define($this->px('WOOCARTFRAGSOFF'), false);
353
354 // woocommerce robots crawling add-to-cart links
355 $this->maybe_define($this->px('WOOADDTOCHARTCRAWLING'), true);
356
357 // woocommerce marketplace / my subscription menu page
358 $this->maybe_define($this->px('WOOEXTENSIONPAGEOFF'), false);
359
360 // post missed schedule
361 $this->maybe_define($this->px('POSTMISSEDSCHEDULE'), false);
362
363 // optimize term count
364 $this->maybe_define($this->px('OPTERMCOUNT'), true);
365
366 // translation mo file cache
367 $this->maybe_define($this->px('MOCACHE'), false);
368
369 // menu cache
370 $this->maybe_define($this->px('MENUCACHE'), false);
371
372 // menu cache ttl: 1209600 = 14 days
373 $this->maybe_define($this->px('MENUCACHE_TTL'), 1209600);
374
375 // @private
376 // wp-cli
377 $this->maybe_define($this->px('WPCLI'), \defined('WP_CLI') && WP_CLI);
378
379 // banner
380 $this->maybe_define($this->px('SIGNATURE'), true);
381
382 // preload
383 $this->maybe_define($this->px('PRELOAD'), false);
384
385 // page loader
386 $this->maybe_define($this->px('PAGELOADER'), true);
387
388 // docket cronbot
389 $this->maybe_define($this->px('CRONBOT'), true);
390
391 // docket cronbot
392 $this->maybe_define($this->px('CRONBOT_MAX'), 10);
393
394 // opcviewer
395 $this->maybe_define($this->px('OPCVIEWER'), false);
396
397 // opcviewer show all
398 $this->maybe_define($this->px('OPCVIEWER_SHOWALL'), false);
399
400 // cache stats
401 $this->maybe_define($this->px('STATS'), true);
402
403 // gc action button
404 $this->maybe_define($this->px('GCACTION'), false);
405
406 // additional flush cache button
407 $this->maybe_define($this->px('FLUSHACTION'), false);
408
409 // check version
410 $this->maybe_define($this->px('CHECKVERSION'), false);
411
412 // / @private: auto update
413 // 28012023: DOCKET_CACHE_AUTOUPDATE only to force WP auto_update_plugin filter.
414 // DOCKET_CACHE_AUTOUPDATE_TOGGLE will sync with WP auto_update_plugins option.
415 // $this->maybe_define($this->px('AUTOUPDATE'), false);
416 $this->maybe_define($this->px('AUTOUPDATE_TOGGLE'), false);
417
418 // flush opcache when deactivate
419 $this->maybe_define($this->px('OPCSHUTDOWN'), false);
420
421 // optimize post query
422 $this->maybe_define($this->px('OPTWPQUERY'), true);
423
424 // limit bulk edit
425 $this->maybe_define($this->px('LIMITBULKEDIT'), false);
426
427 // limit bulk edit bulk limit
428 $this->maybe_define($this->px('LIMITBULKEDIT_LIMIT'), 100);
429
430 // xmlrpc pingbacks
431 $this->maybe_define($this->px('PINGBACK'), true);
432
433 // header junk
434 $this->maybe_define($this->px('HEADERJUNK'), true);
435
436 // wp emoji
437 $this->maybe_define($this->px('WPEMOJI'), false);
438
439 // wp embed
440 $this->maybe_define($this->px('WPEMBED'), false);
441
442 // wp feed
443 $this->maybe_define($this->px('WPFEED'), false);
444
445 // wp lazyload
446 $this->maybe_define($this->px('WPLAZYLOAD'), false);
447
448 // wp sitemap
449 $this->maybe_define($this->px('WPSITEMAP'), false);
450
451 // wp sitemap
452 $this->maybe_define($this->px('WPDASHBOARDNEWS'), false);
453
454 // wp application password: wp >= 5.6
455 $this->maybe_define($this->px('WPAPPPASSWORD'), false);
456
457 // limit http request from uncommon page.
458 $this->maybe_define($this->px('LIMITHTTPREQUEST'), false);
459
460 // whitelist host from limit http request.
461 $this->maybe_define($this->px('LIMITHTTPREQUEST_WHITELIST'), []/* ['feeds.feedburner.com'] */);
462
463 // wp browse-happy
464 $this->maybe_define($this->px('WPBROWSEHAPPY'), false);
465
466 // wp serve-happy
467 $this->maybe_define($this->px('WPSERVEHAPPY'), false);
468
469 // post vis email
470 $this->maybe_define($this->px('POSTVIAEMAIL'), false);
471
472 // cache http response from wp_remote_request.
473 $this->maybe_define($this->px('CACHEHTTPRESPONSE'), false);
474
475 // cache http response ttl: 300 = 5 minutes.
476 $this->maybe_define($this->px('CACHEHTTPRESPONS_TTL'), 300);
477
478 // cache http include list, if empty any url will include.
479 $this->maybe_define($this->px('CACHEHTTPRESPONS_INCLUDE'), []);
480
481 // cache http exclude list.
482 $this->maybe_define($this->px('CACHEHTTPRESPONS_EXCLUDE'), []);
483
484 // @compat: wp version < 6.1 || < 5.8
485 if (isset($GLOBALS['wp_version'])) {
486 if (version_compare($GLOBALS['wp_version'], '6.1', '<')) {
487 // advanced post cache
488 $this->maybe_define($this->px('ADVCPOST'), false);
489
490 // advanced post cache allow post type
491 $this->maybe_define(
492 $this->px('ADVCPOST_POSTTYPE'),
493 [
494 'post',
495 'page',
496 'attachment',
497 'revision',
498 'nav_menu_item',
499 'custom_css',
500 'customize_changeset',
501 'oembed_cache',
502 'user_request',
503 'wp_block',
504 'wp_template',
505 'wp_template_part',
506 'wp_global_styles',
507 'wp_navigation',
508 ]
509 );
510
511 // advanced post cache allow all post type
512 $this->maybe_define($this->px('ADVCPOST_POSTTYPE_ALL'), false);
513 }
514
515 if (version_compare($GLOBALS['wp_version'], '5.8', '<')) {
516 // curl "Expect" header performance tweak
517 $this->maybe_define($this->px('HTTPHEADERSEXPECT'), false);
518 }
519 }
520
521 // @private: auto save interval.
522 $this->maybe_define($this->px('RTPOSTAUTOSAVE'), 1);
523
524 // @private: post revision.
525 $this->maybe_define($this->px('RTPOSTREVISION'), 'on');
526
527 // @private: empty trash.
528 $this->maybe_define($this->px('RTPOSTEMPTYTRASH'), 30);
529
530 // @private: plugin / theme editor.
531 $this->maybe_define($this->px('RTPLUGINTHEMEEDITOR'), \defined('DISALLOW_FILE_EDIT') && DISALLOW_FILE_EDIT ? 'on' : 'off');
532
533 // @private: plugin / theme install.
534 $this->maybe_define($this->px('RTPLUGINTHEMEINSTALL'), \defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS ? 'on' : 'off');
535
536 // @private: overwrite image after edit.
537 $this->maybe_define($this->px('RTIMAGEOVERWRITE'), \defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ? 'on' : 'off');
538
539 // @private: wp debug.
540 $this->maybe_define($this->px('RTWPDEBUG'), \defined('WP_DEBUG') && WP_DEBUG ? 'on' : 'off');
541
542 // @private: wp debug display.
543 $this->maybe_define($this->px('RTWPDEBUGDISPLAY'), \defined('WP_DEBUG_DISPLAY') && WP_DEBUG_DISPLAY ? 'on' : 'off');
544
545 // @private: wp debug log.
546 $this->maybe_define($this->px('RTWPDEBUGLOG'), \defined('WP_DEBUG_LOG') && WP_DEBUG_LOG ? 'on' : 'off');
547
548 // @private: deactivate wp auto update core.
549 $this->maybe_define($this->px('RTWPCOREUPDATE'), \defined('WP_AUTO_UPDATE_CORE') && WP_AUTO_UPDATE_CORE ? 'off' : 'on');
550
551 // @private: deactivate concatenate wp-admin scripts.
552 $this->maybe_define($this->px('RTCONCATENATESCRIPTS'), \defined('CONCATENATE_SCRIPTS') && !(bool) CONCATENATE_SCRIPTS ? 'on' : 'off');
553
554 // @private: deactivate wp cron.
555 $this->maybe_define($this->px('RTDISABLEWPCRON'), \defined('DISABLE_WP_CRON') && DISABLE_WP_CRON ? 'on' : 'off');
556
557 // @private
558 // capture fatal error rarely incase non-throwable
559 // set true for debugging only
560 $this->maybe_define($this->px('CAPTURE_FATALERROR'), false);
561 }
562 }
563