Skip to content
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

Not clearing cache after upgrading to php 8.1.13 + cachetool 9.1 #235

Closed
Herz3h opened this issue Sep 26, 2023 · 7 comments
Closed

Not clearing cache after upgrading to php 8.1.13 + cachetool 9.1 #235

Herz3h opened this issue Sep 26, 2023 · 7 comments

Comments

@Herz3h
Copy link

Herz3h commented Sep 26, 2023

It used to work fine with php 7.4, now it doesn't anymore, i change a php file and run cachetool opcache:reset -vvv and here is the output:

Box Requirements Checker
========================

> Using PHP 8.1.13
> PHP is using the following php.ini file:
  /usr/local/etc/php/php.ini

> Checking Box requirements:
  ✔ The application requires a version matching ">=8.1.0".
  ✔ The package "hollodotme/fast-cgi-client" requires the extension "json".
  ✔ The package "symfony/dependency-injection" conflicts with the extension "psr".
  ✔ The package "symfony/service-contracts" conflicts with the extension "psr".


 [OK] Your system is ready to run the application.


[2023-09-26T12:07:51.487565+02:00] cachetool.INFO: CacheTool 9.1.0 [] []
[2023-09-26T12:07:51.488794+02:00] cachetool.DEBUG: Config: {"adapter":"fastcgi","extensions":["apcu","opcache"],"temp_dir":null,"fastcgi":null,"fastcgiChroot":null,"webClient":null,"webPath":null,"webUrl":null,"webAllowInsecure":null,"webBasicAuth":null,"webHost":null,"http":null} [] []
[2023-09-26T12:07:51.490557+02:00] cachetool.INFO: Adding Proxy: CacheTool\Proxy\ApcuProxy [] []
[2023-09-26T12:07:51.490724+02:00] cachetool.INFO: Adding Proxy: CacheTool\Proxy\PhpProxy [] []
[2023-09-26T12:07:51.490886+02:00] cachetool.INFO: Adding Proxy: CacheTool\Proxy\OpcacheProxy [] []
[2023-09-26T12:07:51.490936+02:00] cachetool.INFO: Setting adapter: CacheTool\Adapter\FastCGI [] []
[2023-09-26T12:07:51.492535+02:00] cachetool.NOTICE: Executing: extension_loaded("Zend OPcache") [] []
[2023-09-26T12:07:51.492602+02:00] cachetool.INFO: Loading Proxy: CacheTool\Proxy\ApcuProxy [] []
[2023-09-26T12:07:51.492643+02:00] cachetool.DEBUG: Loading Function: apcu_add [] []
[2023-09-26T12:07:51.492674+02:00] cachetool.DEBUG: Loading Function: apcu_cache_info [] []
[2023-09-26T12:07:51.492701+02:00] cachetool.DEBUG: Loading Function: apcu_regexp_get_keys [] []
[2023-09-26T12:07:51.492727+02:00] cachetool.DEBUG: Loading Function: apcu_cas [] []
[2023-09-26T12:07:51.492752+02:00] cachetool.DEBUG: Loading Function: apcu_clear_cache [] []
[2023-09-26T12:07:51.492777+02:00] cachetool.DEBUG: Loading Function: apcu_dec [] []
[2023-09-26T12:07:51.492801+02:00] cachetool.DEBUG: Loading Function: apcu_delete [] []
[2023-09-26T12:07:51.492825+02:00] cachetool.DEBUG: Loading Function: apcu_regexp_delete [] []
[2023-09-26T12:07:51.492845+02:00] cachetool.DEBUG: Loading Function: apcu_exists [] []
[2023-09-26T12:07:51.492865+02:00] cachetool.DEBUG: Loading Function: apcu_fetch [] []
[2023-09-26T12:07:51.492893+02:00] cachetool.DEBUG: Loading Function: apcu_inc [] []
[2023-09-26T12:07:51.492915+02:00] cachetool.DEBUG: Loading Function: apcu_sma_info [] []
[2023-09-26T12:07:51.492942+02:00] cachetool.DEBUG: Loading Function: apcu_store [] []
[2023-09-26T12:07:51.492966+02:00] cachetool.DEBUG: Loading Function: apcu_version [] []
[2023-09-26T12:07:51.492991+02:00] cachetool.INFO: Loading Proxy: CacheTool\Proxy\PhpProxy [] []
[2023-09-26T12:07:51.493054+02:00] cachetool.DEBUG: Loading Function: extension_loaded [] []
[2023-09-26T12:07:51.493086+02:00] cachetool.DEBUG: Loading Function: ini_get [] []
[2023-09-26T12:07:51.493112+02:00] cachetool.DEBUG: Loading Function: ini_set [] []
[2023-09-26T12:07:51.493136+02:00] cachetool.DEBUG: Loading Function: phpversion [] []
[2023-09-26T12:07:51.493158+02:00] cachetool.DEBUG: Loading Function: stat_realpath_get [] []
[2023-09-26T12:07:51.493180+02:00] cachetool.DEBUG: Loading Function: stat_realpath_size [] []
[2023-09-26T12:07:51.493202+02:00] cachetool.DEBUG: Loading Function: stat_cache_clear [] []
[2023-09-26T12:07:51.493227+02:00] cachetool.DEBUG: Loading Function: _eval [] []
[2023-09-26T12:07:51.493247+02:00] cachetool.INFO: Loading Proxy: CacheTool\Proxy\OpcacheProxy [] []
[2023-09-26T12:07:51.493282+02:00] cachetool.DEBUG: Loading Function: opcache_compile_file [] []
[2023-09-26T12:07:51.493311+02:00] cachetool.DEBUG: Loading Function: opcache_compile_files [] []
[2023-09-26T12:07:51.493342+02:00] cachetool.DEBUG: Loading Function: opcache_get_configuration [] []
[2023-09-26T12:07:51.493364+02:00] cachetool.DEBUG: Loading Function: opcache_get_status [] []
[2023-09-26T12:07:51.493384+02:00] cachetool.DEBUG: Loading Function: opcache_invalidate [] []
[2023-09-26T12:07:51.493408+02:00] cachetool.DEBUG: Loading Function: opcache_invalidate_many [] []
[2023-09-26T12:07:51.493428+02:00] cachetool.DEBUG: Loading Function: opcache_reset [] []
[2023-09-26T12:07:51.493447+02:00] cachetool.DEBUG: Loading Function: opcache_version [] []
[2023-09-26T12:07:51.493585+02:00] cachetool.DEBUG: Executing code: return extension_loaded('Zend OPcache'); [] []
[2023-09-26T12:07:51.493680+02:00] cachetool.INFO: FastCGI: Dumped code to file: /dev/shm/cachetool-6512ad77788351.01334931.php [] []
[2023-09-26T12:07:51.493767+02:00] cachetool.INFO: FastCGI: Requesting FPM using socket: 127.0.0.1:9000 [] []
[2023-09-26T12:07:51.498515+02:00] cachetool.DEBUG: FastCGI: Response: {} [] []
[2023-09-26T12:07:51.498652+02:00] cachetool.DEBUG: Return errors: [] [] []
[2023-09-26T12:07:51.498685+02:00] cachetool.DEBUG: Return result: true [] []
[2023-09-26T12:07:51.498719+02:00] cachetool.NOTICE: Executing: opcache_reset() [] []
[2023-09-26T12:07:51.498767+02:00] cachetool.DEBUG: Executing code: opcache_reset(); return true; [] []
[2023-09-26T12:07:51.498852+02:00] cachetool.INFO: FastCGI: Dumped code to file: /dev/shm/cachetool-6512ad7779c697.25463665.php [] []
[2023-09-26T12:07:51.498927+02:00] cachetool.INFO: FastCGI: Requesting FPM using socket: 127.0.0.1:9000 [] []
[2023-09-26T12:07:51.499311+02:00] cachetool.DEBUG: FastCGI: Response: {} [] []
[2023-09-26T12:07:51.499392+02:00] cachetool.DEBUG: Return errors: [] [] []
[2023-09-26T12:07:51.499435+02:00] cachetool.DEBUG: Return result: true [] []
PHP 8.1.13 (cli) (built: Nov 29 2022 03:14:40) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.13, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.13, Copyright (c), by Zend Technologies

opcache.ini:

# opcache.ini
[opcache]
opcache.enable=1
opcache.enable_cli=1

; maximum memory that OPcache can use to store compiled PHP files, Symfony recommends 256
opcache.memory_consumption=256

; maximum number of files that can be stored in the cache
opcache.max_accelerated_files=20000

; validate on every request
opcache.revalidate_freq=0

; re-validate of timestamps, is set to false (0) by default, is overridden in local docker-compose
opcache.validate_timestamps=0

opcache.interned_strings_buffer=16

opcache.fast_shutdown=1

; php.ini
opcache.preload=/var/www/html/preload.php

; required for opcache.preload:
opcache.preload_user=www-data

I have tried different cachetool versions, same, it doesn't clear the cache. Only calling: killall -USR2 php-fpm works. Any idea what could be the issue? where to start looking ?

@Herz3h Herz3h changed the title Not clearing cache after upgrading to php 8.1.13 Not clearing cache after upgrading to php 8.1.13 + cachetool 9.1 Sep 26, 2023
@gordalina
Copy link
Owner

Run these commands with a warm cache and show me the output.

Locally I can see that num_cached_keys went from ~1800 to 0, showing that opcache_reset() was successful.

bin/cachetool php:eval --run='return var_export(opcache_get_status()["opcache_statistics"], true);'
bin/cachetool php:eval --run='opcache_reset();'
bin/cachetool php:eval --run='return var_export(opcache_get_status()["opcache_statistics"], true);'

@Herz3h
Copy link
Author

Herz3h commented Oct 5, 2023

Output for cachetool opcache:status:

+----------------------+---------------------------------+
| Name                 | Value                           |
+----------------------+---------------------------------+
| Enabled              | Yes                             |
| Cache full           | No                              |
| Restart pending      | No                              |
| Restart in progress  | No                              |
| Memory used          | 102.39 MiB                      |
| Memory free          | 153.61 MiB                      |
| Memory wasted (%)    | 0 b (0%)                        |
| Strings buffer size  | 12 MiB                          |
| Strings memory used  | 8.38 MiB                        |
| Strings memory free  | 3.62 MiB                        |
| Number of strings    | 120684                          |
+----------------------+---------------------------------+
| Cached scripts       | 11472                           |
| Cached keys          | 12476                           |
| Max cached keys      | 32531                           |
| Start time           | Thu, 28 Sep 2023 22:55:59 +0200 |
| Last restart time    | Thu, 28 Sep 2023 23:12:44 +0200 |
| Oom restarts         | 0                               |
| Hash restarts        | 0                               |
| Manual restarts      | 2                               |
| Hits                 | 4527408                         |
| Misses               | 7807                            |
| Blacklist misses (%) | 0 (0%)                          |
| Opcache hit rate     | 99.827858216204                 |
+----------------------+---------------------------------+
cachetool php:eval --run='return var_export(opcache_get_status()["opcache_statistics"], true);'
array (
  'num_cached_scripts' => 11472,
  'num_cached_keys' => 12476,
  'max_cached_keys' => 32531,
  'hits' => 4528098,
  'start_time' => 1695934559,
  'last_restart_time' => 1695935564,
  'oom_restarts' => 0,
  'hash_restarts' => 0,
  'manual_restarts' => 2,
  'misses' => 7808,
  'blacklist_misses' => 0,
  'blacklist_miss_ratio' => 0.0,
  'opcache_hit_rate' => 99.82786239397377,
)
cachetool php:eval --run='opcache_reset();'
cachetool php:eval --run='return var_export(opcache_get_status()["opcache_statistics"], true);'
array (
  'num_cached_scripts' => 3705,
  'num_cached_keys' => 3705,
  'max_cached_keys' => 32531,
  'hits' => 0,
  'start_time' => 1695934559,
  'last_restart_time' => 1696492288,
  'oom_restarts' => 0,
  'hash_restarts' => 0,
  'manual_restarts' => 3,
  'misses' => 1,
  'blacklist_misses' => 0,
  'blacklist_miss_ratio' => 0.0,
  'opcache_hit_rate' => 0.0,
)

Also, it seems like that opcache_reset() does not reset opcache. Maybe it does for one php-fpm process only (bug) in my case ?

@gordalina
Copy link
Owner

@Herz3h it does seem that it cleaned the cache, see the cached keys is the same as cached scripts, and the hit counter was reset.

There seem to be some cached scripts which you can check which ones by running cachetool opcache:status:scripts.

@Herz3h
Copy link
Author

Herz3h commented Oct 31, 2023

I have a php file where I add (let's call it test.php):

var_dump('test');
die;

After which I run cachetool opcache:reset but it's acting as if I didn't add anything to that file and upon running (cachetool opcache:status:scripts after cachetool opcache:reset), the file where I added the var_dump (test.php) has a HIT value of 0

@gordalina
Copy link
Owner

You need to have the FPM call the file test.php so it can cache it. It should only have a hit=1 on the second call to the file.

@Herz3h
Copy link
Author

Herz3h commented Nov 3, 2023

I'm loading the page through the browser, and even after it is being cached, it doesn't take into account the code I changed, how should I further debug this ? I have tried upgrading to php 8.1.24, same thing

@Herz3h
Copy link
Author

Herz3h commented Nov 10, 2023

@gordalina Removing these two lines fixes the problem, not sure why:

; php.ini
opcache.preload=/var/www/html/preload.php

; required for opcache.preload:
opcache.preload_user=www-data

Content of preload.php:

https://github.com/symfony/recipes/blob/main/symfony/framework-bundle/5.4/config/preload.php

Edit: Problem solved, I had to put the preload.php file inside my project not in a random spot on the filesystem..... (i used /var/www/html/preload.php before, now I used /var/www/symfony/preload.php

Thank you for the assistance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants