Feature #57258
closedClear "web opcode cache" from CLI
Added by Alexander Opitz over 10 years ago. Updated almost 8 years ago.
0%
Description
The opcode cache from the web process cannot be cleared in CLI mode. You need to call the web process directly (fopen/curl) or by socket (if available PHP-FPM).
Its needed for example if we add/remove an extension via CLI and the regenerated cache needs to be wiped out of opcode cache.
Updated by Alexander Opitz about 9 years ago
- Target version changed from next-patchlevel to 8 LTS
Updated by Helmut Hummel over 8 years ago
- Status changed from Accepted to Needs Feedback
You need to call the web process directly (fopen/curl) or by socket (if available PHP-FPM)
How is the (rough) idea how this could be done in a generic enough way to be implemented into TYPO3?
Updated by Mathias Brodala over 8 years ago
I don't think we need a TYPO3 specific solution here. There are already existing solutions like the Cachetool which should be evaluated first.
Updated by Alexander Opitz over 8 years ago
Ok, nice tool, but seams not to work for PHP as Apache module.
On the other side, TYPO3 with PHP-FPM, is also problematic, as it only clears the opcode cache of the running FPM which got the clear call and not on all instances. :(
This both issues are independent of the used opcode cache.
Updated by Helmut Hummel over 8 years ago
Here are my ideas on that topic:
- We write a script (completely TYPO3 independent), which reliably clears opcode caches, when requested with any sapi (fcgi, fpm, mod_php, cli) for that respective sapi
- We secure it with a token, which is valid for only 30 seconds. Caches are only cleared if token is valid
- We change our code that only a (lightwight) event is triggered when opcache should be cleared
- By default (certain extension maybe) we register a listener, which calls this script from a (configured or detected) URL with a token provided
Benefit:
- Default listener can be removed if not needed
- Other listeners can do custom stuff (see #66495)
- Cleaner, more decoupled code with better functionality
Updated by Alexander Opitz over 8 years ago
@Mathias
The tool also won't work for fpm, if you aren't in the group of the running webserver. As you can't open the socket to write too. So it seams this won't work by hosters.
Also in the last days I got issues, with PHP7 on cli and PHP5.6 on mod_php, sometimes I hate customers which change their environments without inform us. ;)
So it seams, we will need a web endpoint for every sapi to handle this.
On the other side, this leads, for me, to the result, that APCu/Xcache (user cache) isn't useable on fpm, as the fpm instances do not synchronize?
Updated by Helmut Hummel over 8 years ago
or: we remove all opcode cache clearing code and advice users not to use opcode caches (or clear them manually after deployment)
Updated by Markus Klein over 8 years ago
From the Slack discussion:
my conclusion:
- opcache is a good thing
- never clear all opcode caches, if not necessary
- only the admin knows which instances are on the server and which pools actually use a certain path/files (dependency)
- normal users can clear opcache via install tool
- any cli script needs proper post processing by the admin knowing the dependencies of the code and which processes (apache, fpm) are affected
CacheTool actually is just the tool for the admin who knows what to clear, that's already documented in the basic usage of the tool, where one has to define which FPM is to be connected
As long as there is no information available for a CLI tool, which reports the connection between php-file and possibly affected processes, there is no sane way to clear opcode cache automatically. There can always be a setup that is not covered by the script.
Updated by Helmut Hummel over 8 years ago
Markus Klein wrote:
From the Slack discussion:
my conclusion:
- opcache is a good thing
It depends imho. During development they are pretty annoying if configured not to respect file changes (which is the default imho)
- never clear all opcode caches, if not necessary
TYPO3 currently flushes all opcode caches automatically on certain incidents.
This can be a big issue for high traffic sites.
- only the admin knows which instances are on the server and which pools actually use a certain path/files (dependency)
That is exactly why I argue, that TYPO3 cannot do something useful in itself
- normal users can clear opcache via install tool
I would be fine keeping this tool.
- any cli script needs proper post processing by the admin knowing the dependencies of the code and which processes (apache, fpm) are affected
I would abstain from implementing any CLI solution. Do you agree?
CacheTool actually is just the tool for the admin who knows what to clear, that's already documented in the basic usage of the tool, where one has to define which FPM is to be connected
As long as there is no information available for a CLI tool, which reports the connection between php-file and possibly affected processes, there is no sane way to clear opcode cache automatically. There can always be a setup that is not covered by the script.
So you agree to just close this ticket as "won't fix"?
On top of that I would remove all code that clears OPCache "automatically". On low traffic sites the benefit of an OPCache is rather low. On high traffic sites, the impact of clearing the OPCache can be harmful.
But I will not fight for that…
Updated by Markus Klein over 8 years ago
During development ..
I agree of course. My words were more about production.
TYPO3 currently flushes all opcode caches automatically on certain incidents.
I'm not sure how this is implemented in FPM. But if two sites (FPM pools) use different users, I would hope that other user's caches are not affected.
I would abstain from implementing any CLI solution. Do you agree?
Full ACK!
IMO we can close this one.
On top of that I would remove all code that clears OPCache "automatically"
I'm only aware of one place, where we do that, but we only clear a dedicated folder path, I'm fine with that as we do not flush the whole cache.
Updated by Alexander Opitz over 8 years ago
At first, we only clear the complete opcode cache on the button, installing an extension and building the ClassLoader cache crashes (only for 6.2?). Otherwise we clear the opcode cache on a per file base.
Clearing the opcode cache completely means we clear it for the running User (fcgi and fpm after rework) or all (mod_php as there are no different users).
Updating an extensions via CLI needs to clear the opcode cache via CLI. Also other deployment strategies without ExtensionManager seems to need this.
The complete clear for installing extensions may also be reworked to only per file base for all files inside the updated extension.
OPcache is defaulting to check timestamps of files every 2 seconds, you can change this to 0 to check on every request or disabling the timestamp checking to never check. Last szenario is the fastest one for High Traffic sites.
Updated by Riccardo De Contardi almost 8 years ago
- Status changed from Needs Feedback to Closed
- Assignee deleted (
Alexander Opitz)
As stated on the last comments, clearing the web opcache from CLI is not really doable on TYPO3, therefore, I am closing this one.
Some solutions you could try are:
https://github.com/TYPO3/Surf/blob/87999f6/src/Task/Php/WebOpcacheResetExecuteTask.php
https://github.com/gordalina/cachetool
If you think that this is the wrong decision or that there is still work to be done, please reopen it or open a new issue with a reference to this one. Thank you.