-
Notifications
You must be signed in to change notification settings - Fork 3.4k
OPcache: Add information to the Site Health -> Server #9260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 18 commits
24a96cd
b530158
231515b
2ef962d
620c687
e35fe8a
d546cb4
1ea330c
232ea64
152e81a
63f41ea
923db6f
801cbee
5ad77f9
0887bc7
3fd57b9
4675ff5
e62c774
4320d86
4a39b00
c3ef929
b8ee643
dd325c4
0dae7c5
fc5cf45
17e5a79
1e6815b
cb95231
8b1d774
6cd176b
677a434
2c7dee1
6ef53de
a282d58
4362720
8eaebf3
57dcb5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -471,6 +471,56 @@ private static function get_wp_server(): array { | |
| 'debug' => $imagick_loaded, | ||
| ); | ||
|
|
||
| // Opcode Cache. | ||
| if ( function_exists( 'opcache_get_status' ) ) { | ||
| $opcache_status = @opcache_get_status( false ); | ||
|
|
||
| if ( false === $opcache_status ) { | ||
| $fields['opcode_cache'] = array( | ||
| 'label' => __( 'Opcode cache' ), | ||
| 'value' => __( 'Disabled by configuration' ), | ||
| 'debug' => 'not available', | ||
| ); | ||
| } else { | ||
| $fields['opcode_cache'] = array( | ||
| 'label' => __( 'Opcode cache' ), | ||
| 'value' => ( $opcache_status['opcache_enabled'] ? __( 'Enabled' ) : __( 'Disabled' ) ), | ||
|
rollybueno marked this conversation as resolved.
Outdated
rollybueno marked this conversation as resolved.
Outdated
|
||
| 'debug' => $opcache_status['opcache_enabled'], | ||
|
westonruter marked this conversation as resolved.
|
||
| ); | ||
|
|
||
| $fields['opcode_cache_memory_usage'] = array( | ||
| 'label' => __( 'Opcode cache memory usage' ), | ||
| 'value' => sprintf( | ||
| /* translators: 1: Used memory, 2: Total memory */ | ||
| __( '%1$s of %2$s' ), | ||
| size_format( $opcache_status['memory_usage']['used_memory'] ), | ||
| size_format( $opcache_status['memory_usage']['free_memory'] + $opcache_status['memory_usage']['used_memory'] ) | ||
| ), | ||
| 'debug' => sprintf( | ||
| '%s of %s', | ||
| $opcache_status['memory_usage']['used_memory'], | ||
| $opcache_status['memory_usage']['free_memory'] + $opcache_status['memory_usage']['used_memory'] | ||
| ), | ||
| ); | ||
|
|
||
| $fields['opcode_cache_hit_rate'] = array( | ||
| 'label' => __( 'Opcode cache hit rate' ), | ||
| 'value' => sprintf( | ||
| /* translators: %s: Hit rate percentage */ | ||
| __( '%s%%' ), | ||
| round( $opcache_status['opcache_statistics']['opcache_hit_rate'], 2 ) | ||
| ), | ||
| 'debug' => $opcache_status['opcache_statistics']['opcache_hit_rate'], | ||
| ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on https://www.php.net/manual/en/function.opcache-get-status.php, these keys should still be accessible even when the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively, shouldn't
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In other words, wrap these two assignments with a
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's correct - I'm wrapping this inside if statement
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added the conditional extra info only if the |
||
| } | ||
| } else { | ||
| $fields['opcode_cache'] = array( | ||
| 'label' => __( 'Opcode cache' ), | ||
| 'value' => __( 'Disabled' ), | ||
| 'debug' => 'not available', | ||
| ); | ||
| } | ||
|
|
||
| // Pretty permalinks. | ||
| $pretty_permalinks_supported = got_url_rewrite(); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2730,6 +2730,50 @@ public function get_test_search_engine_visibility() { | |
| return $result; | ||
| } | ||
|
|
||
| /** | ||
| * Tests if opcode cache is enabled and available. | ||
| * | ||
| * @since 6.9.0 | ||
|
rollybueno marked this conversation as resolved.
Outdated
|
||
| * | ||
| * @return array The test result. | ||
|
rollybueno marked this conversation as resolved.
Outdated
|
||
| */ | ||
| public function get_test_opcode_cache() { | ||
| $opcode_cache_enabled = false; | ||
| if ( function_exists( 'opcache_get_status' ) ) { | ||
| $status = opcache_get_status( false ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Used the same logic as on the |
||
| $opcode_cache_enabled = $status['opcache_enabled']; | ||
| } | ||
|
|
||
| $result = array( | ||
| 'label' => __( 'Opcode cache is enabled' ), | ||
| 'status' => 'good', | ||
| 'badge' => array( | ||
| 'label' => __( 'Performance' ), | ||
| 'color' => 'blue', | ||
| ), | ||
| 'description' => sprintf( | ||
| '<p>%s</p>', | ||
| __( 'Opcode cache improves PHP performance by storing precompiled script bytecode in memory, reducing the need for PHP to load and parse scripts on each request.' ) | ||
| ), | ||
| 'actions' => sprintf( | ||
| '<p><a href="%s" target="_blank">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>', | ||
| 'https://www.php.net/manual/en/book.opcache.php', | ||
|
rollybueno marked this conversation as resolved.
Outdated
|
||
| __( 'Learn more about OPcache.' ), | ||
| /* translators: Hidden accessibility text. */ | ||
| __( '(opens in a new tab)' ) | ||
| ), | ||
| 'test' => 'opcache', | ||
|
rollybueno marked this conversation as resolved.
Outdated
|
||
| ); | ||
|
|
||
| if ( ! $opcode_cache_enabled ) { | ||
| $result['status'] = 'recommended'; | ||
| $result['label'] = __( 'Opcode cache is not enabled' ); | ||
| $result['description'] .= '<p>' . __( 'Opcode cache is not enabled. Enabling this cache can significantly improve the performance of your site.' ) . '</p>'; | ||
|
rollybueno marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| return $result; | ||
| } | ||
|
|
||
| /** | ||
| * Returns a set of tests that belong to the site status page. | ||
| * | ||
|
|
@@ -2822,6 +2866,10 @@ public static function get_tests() { | |
| 'label' => __( 'Search Engine Visibility' ), | ||
| 'test' => 'search_engine_visibility', | ||
| ), | ||
| 'opcode_cache' => array( | ||
| 'label' => __( 'Opcode cache' ), | ||
| 'test' => 'opcode_cache', | ||
| ), | ||
| ), | ||
| 'async' => array( | ||
| 'dotorg_communication' => array( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.