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

Show info in admin settings about PHP opcache if disabled #3489

Merged
merged 1 commit into from
Feb 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions core/js/setupchecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,18 @@
type: OC.SetupChecks.MESSAGE_TYPE_ERROR
});
}
if(!data.isOpcacheProperlySetup) {
messages.push({
msg: t(
'core',
'The PHP Opcache is not properly configured. <a target="_blank" rel="noreferrer" href="{docLink}">For better performance we recommend ↗</a> to use following settings in the <code>php.ini</code>:',
{
docLink: data.phpOpcacheDocumentation,
}
) + "<pre><code>opcache.enable=On\nopcache.enable_cli=1\nopcache.interned_strings_buffer=8\nopcache.max_accelerated_files=10000\nopcache.memory_consumption=128\nopcache.save_comments=1\nopcache.revalidate_freq=1</code></pre>",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opcache.enabled=On and opcache.enabled_cli=1? Can you make both 1?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No - this somehow doesn't work. opcache.enabled works here on Ubuntu 16.04 only with On ... all other options with 1. I'm confused as well 😕

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http://php.net/manual/en/opcache.configuration.php really odd then:

Name 	Default 	Changeable 	Changelog
opcache.enable 	"1" 	PHP_INI_ALL 	 

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http://php.net/manual/en/opcache.configuration.php really odd then:

I know. But better be on the safe side for this.

type: OC.SetupChecks.MESSAGE_TYPE_INFO
});
}
} else {
messages.push({
msg: t('core', 'Error occurred while checking server setup'),
Expand Down
37 changes: 37 additions & 0 deletions core/js/tests/specs/setupchecksSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ describe('OC.SetupChecks tests', function() {
forwardedForHeadersWorking: true,
isCorrectMemcachedPHPModuleInstalled: true,
hasPassedCodeIntegrityCheck: true,
isOpcacheProperlySetup: true,
})
);

Expand Down Expand Up @@ -186,6 +187,7 @@ describe('OC.SetupChecks tests', function() {
forwardedForHeadersWorking: true,
isCorrectMemcachedPHPModuleInstalled: true,
hasPassedCodeIntegrityCheck: true,
isOpcacheProperlySetup: true,
})
);

Expand Down Expand Up @@ -218,6 +220,7 @@ describe('OC.SetupChecks tests', function() {
forwardedForHeadersWorking: true,
isCorrectMemcachedPHPModuleInstalled: true,
hasPassedCodeIntegrityCheck: true,
isOpcacheProperlySetup: true,
})
);

Expand Down Expand Up @@ -248,6 +251,7 @@ describe('OC.SetupChecks tests', function() {
forwardedForHeadersWorking: true,
isCorrectMemcachedPHPModuleInstalled: true,
hasPassedCodeIntegrityCheck: true,
isOpcacheProperlySetup: true,
})
);

Expand Down Expand Up @@ -276,6 +280,7 @@ describe('OC.SetupChecks tests', function() {
forwardedForHeadersWorking: true,
isCorrectMemcachedPHPModuleInstalled: false,
hasPassedCodeIntegrityCheck: true,
isOpcacheProperlySetup: true,
})
);

Expand Down Expand Up @@ -304,6 +309,7 @@ describe('OC.SetupChecks tests', function() {
reverseProxyDocs: 'https://docs.owncloud.org/foo/bar.html',
isCorrectMemcachedPHPModuleInstalled: true,
hasPassedCodeIntegrityCheck: true,
isOpcacheProperlySetup: true,
})
);

Expand Down Expand Up @@ -353,6 +359,7 @@ describe('OC.SetupChecks tests', function() {
phpSupported: {eol: true, version: '5.4.0'},
isCorrectMemcachedPHPModuleInstalled: true,
hasPassedCodeIntegrityCheck: true,
isOpcacheProperlySetup: true,
})
);

Expand All @@ -364,6 +371,36 @@ describe('OC.SetupChecks tests', function() {
done();
});
});

it('should return an info if server has no proper opcache', function(done) {
var async = OC.SetupChecks.checkSetup();

suite.server.requests[0].respond(
200,
{
'Content-Type': 'application/json'
},
JSON.stringify({
isUrandomAvailable: true,
securityDocs: 'https://docs.owncloud.org/myDocs.html',
serverHasInternetConnection: true,
isMemcacheConfigured: true,
forwardedForHeadersWorking: true,
isCorrectMemcachedPHPModuleInstalled: true,
hasPassedCodeIntegrityCheck: true,
isOpcacheProperlySetup: false,
phpOpcacheDocumentation: 'https://example.org/link/to/doc',
})
);

async.done(function( data, s, x ){
expect(data).toEqual([{
msg: 'The PHP Opcache is not properly configured. <a target="_blank" rel="noreferrer" href="https://example.org/link/to/doc">For better performance we recommend ↗</a> to use following settings in the <code>php.ini</code>:' + "<pre><code>opcache.enable=On\nopcache.enable_cli=1\nopcache.interned_strings_buffer=8\nopcache.max_accelerated_files=10000\nopcache.memory_consumption=128\nopcache.save_comments=1\nopcache.revalidate_freq=1</code></pre>",
type: OC.SetupChecks.MESSAGE_TYPE_INFO
}]);
done();
});
});
});

describe('checkGeneric', function() {
Expand Down
39 changes: 39 additions & 0 deletions settings/Controller/CheckSetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

namespace OC\Settings\Controller;

use bantu\IniGetWrapper\IniGetWrapper;
use GuzzleHttp\Exception\ClientException;
use OC\AppFramework\Http;
use OC\IntegrityCheck\Checker;
Expand Down Expand Up @@ -354,6 +355,42 @@ public function getFailedIntegrityCheckFiles() {
return $response;
}

/**
* Checks whether a PHP opcache is properly set up
* @return bool
*/
private function isOpcacheProperlySetup() {
$iniWrapper = new IniGetWrapper();

$isOpcacheProperlySetUp = true;

if(!$iniWrapper->getBool('opcache.enable')) {
$isOpcacheProperlySetUp = false;
}

if(!$iniWrapper->getBool('opcache.save_comments')) {
$isOpcacheProperlySetUp = false;
}

if(!$iniWrapper->getBool('opcache.enable_cli')) {
$isOpcacheProperlySetUp = false;
}

if($iniWrapper->getNumeric('opcache.max_accelerated_files') < 10000) {
$isOpcacheProperlySetUp = false;
}

if($iniWrapper->getNumeric('opcache.memory_consumption') < 128) {
$isOpcacheProperlySetUp = false;
}

if($iniWrapper->getNumeric('opcache.interned_strings_buffer') < 8) {
$isOpcacheProperlySetUp = false;
}

return $isOpcacheProperlySetUp;
}

/**
* @return DataResponse
*/
Expand All @@ -372,6 +409,8 @@ public function check() {
'isCorrectMemcachedPHPModuleInstalled' => $this->isCorrectMemcachedPHPModuleInstalled(),
'hasPassedCodeIntegrityCheck' => $this->checker->hasPassedCheck(),
'codeIntegrityCheckerDocumentation' => $this->urlGenerator->linkToDocs('admin-code-integrity'),
'isOpcacheProperlySetup' => $this->isOpcacheProperlySetup(),
'phpOpcacheDocumentation' => $this->urlGenerator->linkToDocs('admin-php-opcache'),
]
);
}
Expand Down
12 changes: 11 additions & 1 deletion tests/Settings/Controller/CheckSetupControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,14 @@ public function testCheck() {
->method('linkToDocs')
->with('admin-reverse-proxy')
->willReturn('reverse-proxy-doc-link');
$this->urlGenerator->expects($this->at(3))
->method('linkToDocs')
->with('admin-code-integrity')
->willReturn('http://doc.owncloud.org/server/go.php?to=admin-code-integrity');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiny nitpick... but why not use our own domain ;)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the other check I and I would like to keep them in sync with the code above :/

$this->urlGenerator->expects($this->at(4))
->method('linkToDocs')
->with('admin-php-opcache')
->willReturn('http://doc.owncloud.org/server/go.php?to=admin-php-opcache');

$expected = new DataResponse(
[
Expand All @@ -328,7 +336,9 @@ public function testCheck() {
'reverseProxyDocs' => 'reverse-proxy-doc-link',
'isCorrectMemcachedPHPModuleInstalled' => true,
'hasPassedCodeIntegrityCheck' => null,
'codeIntegrityCheckerDocumentation' => null,
'codeIntegrityCheckerDocumentation' => 'http://doc.owncloud.org/server/go.php?to=admin-code-integrity',
'isOpcacheProperlySetup' => false,
'phpOpcacheDocumentation' => 'http://doc.owncloud.org/server/go.php?to=admin-php-opcache',
]
);
$this->assertEquals($expected, $this->checkSetupController->check());
Expand Down