Improved advanced jit output (#80)

* Use `DateTimeImmutable` rather than `date`
* A few minor tidy-ups
* Bump of version in preparation
* Expands on the JIT value
* Updated readme
This commit is contained in:
Andrew Collington 2022-01-09 23:48:23 +00:00 committed by GitHub
parent 5ddcf95388
commit 06ddd7d007
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 118 additions and 45 deletions

View file

@ -4,18 +4,27 @@ A clean and responsive interface for Zend OPcache information, showing statistic
This interface uses ReactJS and Axios and is for modern browsers and requires a minimum of PHP 7.1.
[![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=acollington&url=https://github.com/amnuts/opcache-gui&title=opcache-gui&language=&tags=github&category=software)
If you like this software or find it helpful then maybe you'll consider supporting my efforts in some way by [signing up to Flattr and leaving a micro-donation](https://flattr.com/@acollington).
# License
### Using the opcache-gui
MIT: http://acollington.mit-license.org/
# Sponsoring this work
If you're able and would like to sponsor this work in some way, then feel free to do so through the [GitHub Sponsorship](https://github.com/sponsors/amnuts) page.
Alternatively, if you'd just like to give me a [shout-out on Twitter](https://twitter.com/acollington) to say you use it, that'd be awesome, too! (Any one else miss postcardware?)
# Using the opcache-gui
## Installing
There are two ways to getting started using this gui:
#### Copy/clone this repo
### Copy/clone this repo
The easiest way to start using the opcache-gui is to clone this repo, or simply copy/paste/download the `index.php` file to a location which your web server can load. Then point your browser to that location, such as `https://www.example.com/opcache/index.php`.
#### Install via composer
### Install via composer
You can include the files with [Composer](https://getcomposer.org/) by running the command `composer require amnuts/opcache-gui`.
@ -58,7 +67,7 @@ ln -s /var/www/vendor/amnuts/opcache-gui/index.php /var/www/html/opcache.php
Basically, there are plenty of ways to get the interface up and running - pick whichever suits your needs.
### Configuration
## Configuration
The default configuration for the interface looks like this:
@ -94,7 +103,7 @@ $opcache = (new Service([
]))->handle();
```
### Changing the look
## Changing the look
The interface has been split up to allow you to easily change the colours of the gui, or even the core components, should you wish.
@ -115,6 +124,8 @@ The build process will create a compiled css file at `build/interface.css` and t
The core PHP template used in the build process, and that acts to pass various bits of data to the ReactJS side of things, is located at `build/template.phps`. If you wanted to update the version of ReactJS used, or how the wrapper html is structured, then this would be the file you'd want to update.
## The interface
### Overview
The overview will show you all the core information. From here you'll be able to see what host and platform you're running on, what version of OPcache you're using, when it was last reset, the functions and directives available (with links to the php.net manual), and all the statistics associated with the OPcache (number of hits, memory used, free and wasted memory, and more).
@ -159,7 +170,13 @@ When the real-time updates are active, the interface will automatically update a
Also, if you choose to invalidate any files or reset the cache it will do this without reloading the page, so the search term you've entered, or the page to which you've navigated do not get reset. If the real-time update is not on then the page will reload on any invalidation usage.
## Releases
# Releases
**Version 3.3.1**\
Just a few minor tweaks:
* Added more of an explanation to the JIT value
* Replaced date functions with \DateTime and related classes
* Updated README with troubleshooting and sponsorship info (and refined header levels)
**Version 3.3.0**\
Mostly added JIT information for PHP 8:
@ -250,7 +267,7 @@ Releases of the GUI are available at:
https://github.com/amnuts/opcache-gui/releases/
### Making is compatible with PHP 7.0
# Making is compatible with PHP 7.0
The script requires PHP 7.1 or above. I'm not tempted to downgrade the code to make it compatible with version 7.0, and hopefully most people would have upgraded by now. But I really do appreciate that sometimes people just don't have the ability to change the version of PHP they use because it's out of their control. So if you're one of the unlucky ones, you can make the following changes to `index.php` (or `Service.php` and run the build script). For the lines:
@ -264,6 +281,16 @@ public function resetCache(?string $file = null): bool
It'll just be a case of removing the `?` from each of the params.
# License
# Troubleshooting
MIT: http://acollington.mit-license.org/
## Use of PHP-FPM
A number of people have questioned whether the opcache-gui is working on their instance of PHP-FPM, as the files shown don't appear to be everything that's cached, and that's different to what Apache might show.
Essentially, that's expected behaviour. And thanks to a great comment from contributor [Michalng](https://github.com/amnuts/opcache-gui/issues/78#issuecomment-1008015099), this explanation should cover the difference:
> The interface can only show what it knows about the OPcache usage of its own OPcache instance, hence when it's accessed through Apache with mod_php, then it can only see the OPcache usage of that Apache webserver OPcache instance. When it's accessed with classic CGI, it can only see itself being cached as a new PHP and OPcache instance is created, in which case OPcache itself often doesn't make sense.
>
> To be able to monitor and manage the OPcache for all web applications, all need to use the same FastCGI, i.e. PHP-FPM instance.
>
> In case of Apache, one then often needs to actively configure it to not use it's internal mod_php but send PHP handler requests to the shared PHP-FPM server via mod_proxy_fcgi, which also requires using the event MPM. That is generally seen as the preferred setup nowadays, especially for high traffic websites. This is because every single incoming request with MPM prefork + mod_php creates an own child process taking additional time and memory, while with event MPM and dedicated PHP-FPM server a (usually) already waiting handler thread is used on Apache and on PHP end, consuming nearly no additional memory or time for process spawning.

View file

@ -337,7 +337,9 @@ function Directives(props) {
return (
<ul className="directive-list">{
directive.v.map((item, key) => {
return <li key={key}>{item}</li>
return Array.isArray(item)
? <li key={"sublist_" + key}>{directiveList({v:item})}</li>
: <li key={key}>{item}</li>
})
}</ul>
);

View file

@ -260,6 +260,10 @@ $footer-border-color: #CCC;
&:last-child {
margin-bottom: 0;
}
ul {
margin-top: 1.5em;
}
}
}

View file

@ -4,7 +4,7 @@
* OPcache GUI - build script
*
* @author Andrew Collington, andy@amnuts.com
* @version 3.3.0
* @version 3.3.1
* @link https://github.com/amnuts/opcache-gui
* @license MIT, https://acollington.mit-license.org/
*/

View file

@ -8,7 +8,7 @@ namespace Amnuts\Opcache;
* A simple but effective single-file GUI for the OPcache PHP extension.
*
* @author Andrew Collington, andy@amnuts.com
* @version 3.3.0
* @version 3.3.1
* @link https://github.com/amnuts/opcache-gui
* @license MIT, https://acollington.mit-license.org/
*/

File diff suppressed because one or more lines are too long

View file

@ -2,9 +2,13 @@
namespace Amnuts\Opcache;
use DateTimeImmutable;
use DateTimeZone;
use Exception;
class Service
{
const VERSION = '3.3.0';
public const VERSION = '3.3.1';
protected $data;
protected $options;
@ -68,6 +72,11 @@ class Service
]
]
];
protected $jitModeMapping = [
'tracing' => 1254,
'on' => 1254,
'function' => 1205
];
/**
* Service constructor.
@ -99,6 +108,7 @@ class Service
/**
* @return $this
* @throws Exception
*/
public function handle(): Service
{
@ -113,13 +123,11 @@ class Service
if (isset($_GET['reset']) && $this->getOption('allow_reset')) {
$response($this->resetCache());
} else if (isset($_GET['invalidate']) && $this->getOption('allow_invalidate')) {
} elseif (isset($_GET['invalidate']) && $this->getOption('allow_invalidate')) {
$response($this->resetCache($_GET['invalidate']));
} else if (isset($_GET['invalidate_searched']) && $this->getOption('allow_invalidate')) {
} elseif (isset($_GET['invalidate_searched']) && $this->getOption('allow_invalidate')) {
$response($this->resetSearched($_GET['invalidate_searched']));
} else if (isset($_GET['invalidate_searched']) && $this->getOption('allow_invalidate')) {
$response($this->resetSearched($_GET['invalidate_searched']));
} else if ($this->isJsonRequest() && $this->getOption('allow_realtime')) {
} elseif ($this->isJsonRequest() && $this->getOption('allow_realtime')) {
echo json_encode($this->getData($_GET['section'] ?? null));
exit;
}
@ -171,13 +179,14 @@ class Service
/**
* @param string|null $file
* @return bool
* @throws Exception
*/
public function resetCache(?string $file = null): bool
{
$success = false;
if ($file === null) {
$success = opcache_reset();
} else if (function_exists('opcache_invalidate')) {
} elseif (function_exists('opcache_invalidate')) {
$success = opcache_invalidate(urldecode($file), true);
}
if ($success) {
@ -189,6 +198,7 @@ class Service
/**
* @param string $search
* @return bool
* @throws Exception
*/
public function resetSearched(string $search): bool
{
@ -234,6 +244,7 @@ class Service
/**
* @return array
* @throws Exception
*/
protected function compileState(): array
{
@ -246,7 +257,7 @@ class Service
$files = [];
if (!empty($status['scripts']) && $this->getOption('allow_filelist')) {
uasort($status['scripts'], function ($a, $b) {
uasort($status['scripts'], static function ($a, $b) {
return $a['hits'] <=> $b['hits'];
});
foreach ($status['scripts'] as &$file) {
@ -286,10 +297,14 @@ class Service
'num_cached_keys' => number_format($status['opcache_statistics']['num_cached_keys']),
'max_cached_keys' => number_format($status['opcache_statistics']['max_cached_keys']),
'interned' => null,
'start_time' => date('Y-m-d H:i:s', $status['opcache_statistics']['start_time']),
'start_time' => (new DateTimeImmutable("@{$status['opcache_statistics']['start_time']}"))
->setTimezone(new DateTimeZone(date_default_timezone_get()))
->format('Y-m-d H:i:s'),
'last_restart_time' => ($status['opcache_statistics']['last_restart_time'] == 0
? 'never'
: date('Y-m-d H:i:s', $status['opcache_statistics']['last_restart_time'])
: (new DateTimeImmutable("@{$status['opcache_statistics']['last_restart_time']}"))
->setTimezone(new DateTimeZone(date_default_timezone_get()))
->format('Y-m-d H:i:s')
)
]
]
@ -342,13 +357,16 @@ class Service
}
$v = $levels ?: 'none';
} elseif ($k === 'opcache.jit') {
if (is_numeric($v)) {
if ($v === '1') {
$v = 'on';
}
if (isset($this->jitModeMapping[$v]) || is_numeric($v)) {
$levels = [];
foreach (str_split((string)$v) as $type => $level) {
foreach (str_split((string)($this->jitModeMapping[$v] ?? $v)) as $type => $level) {
$levels[] = "{$level}: {$this->jitModes[$type]['value'][$level]} ({$this->jitModes[$type]['flag']})";
}
$v = $levels;
} elseif (strtolower($v) === 'off' || $v === '') {
$v = [$v, $levels];
} elseif (empty($v) || strtolower($v) === 'off') {
$v = 'Off';
}
}