-
Notifications
You must be signed in to change notification settings - Fork 1k
Check opcache isn't enabled on cli and throw a warning if so. #4156
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
Conversation
|
Related issue: #4103 |
php/WP_CLI/Runner.php
Outdated
|
|
||
| WP_CLI::warning( | ||
| "It looks like you're running this with opcache enabled. \n". | ||
| "This can cause weird behaviour, you can disable it into your php.ini file, search for opcache.enable_cli and set it to 0." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The text should be a bit more specific. Maybe something like this:
"It looks like your PHP CLI runtime has OPcache enabled.\n" .
"This can produce inconsistent behavior and cause random bugs.\n" .
"You can disable OPcache in your php.ini by setting the 'opcache.enable_cli' key to the value 0."
php/WP_CLI/Runner.php
Outdated
| } | ||
|
|
||
| public function check_opcache() { | ||
| if( false === (bool) get_cfg_var( 'opcache.enable_cli' ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code style: if (
tests/test-opcache.php
Outdated
| $runner = new Runner(); | ||
| $this->assertTrue( $runner->check_opcache() ); | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code style: Add new line at the end of files.
tests/test-opcache.php
Outdated
| return false; | ||
| } | ||
|
|
||
| class opCache extends \PHPUnit_Framework_TestCase { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code style: Use StudlyCaps for classes OpCache.
|
Looking at the test, I assume you didn't find a way to actually turn on OPcache at runtime. Can you provide a small comment of what you looked into and why it didn't work, for reference? |
|
Thank you for the pull request! There's only minor code style issues, and I would like the text to be more specific. |
|
Hello, I have tried to make the Namespace WP_CLI before rewriting the function |
|
Nicolas Juen wrote:
Hello,
Yes unfortunately I haven't found a solution for the unit test, the
opcache.cli_enable can only be changed on the php.ini file or in the
httpd.conf file. So it's not possible to do it.
I have tried to make the Namespace WP_CLI before rewriting the function
|get_cfg_var| but in the end, the Runner.php does not found the |WP_CLI|
class itself.
So I have included the |php/class-wp-cli.php| file at the beginning of
the file but not working either unfortunately.
Maybe build a temporary php.ini file making any appropriate changes, then
run php as php --php-ini temp-php.ini file + then destroy the temp file.
A bit ugly + likely this will work.
|
|
Using an environment variable is the wp-cli way to make such functions testable - see eg https://github.com/wp-cli/wp-cli/blob/master/php/utils.php#L513 and https://github.com/wp-cli/wp-cli/blob/master/tests/test-utils.php#L147. (Also some nitpicks - perhaps use the more normal |
|
Actually just tried it with PHP 7.1.4 where Though more importantly this makes a strong case for having Which makes the reliance on comments for basic functionality such as the hooks mechanism a problem, as it doesn't work with as @Demayl could you confirm whether or not So I think in the medium term perhaps move away from using comments for basic functionality such as hooks etc, and use some explicit registration system or something instead - this obviously needs thought and discussion! In the short term Also re the current issue, the Also it should be tested using the |
|
@gitlost |
|
Ta v much - the case for the prosecution grows! |
This would be a substantial undertaking that I'm not sure is warranted. Many parts of WP-CLI (and, subsequently, the WP-CLI ecosystem) are dependent on comments. To refactor would require a huge amount of effort. If the only problem we're faced with is the issue of
Correct. If any PHP configuration would cause WP-CLI to behave inconsistently, then we should error for that PHP configuration. Some prior art #283 (comment) |
I'm guessing there's a good chance it could all be done programmatically - but anyway I'll open an idea about it... |
Check opcache isn't enabled on cli and throw a warning if so.