From cee8853658703358a8e564c414807c632ee0d5ea Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Wed, 15 Feb 2017 00:40:36 -0600 Subject: [PATCH] Show info in admin settings about PHP opcache if disabled Signed-off-by: Morris Jobke --- core/js/setupchecks.js | 12 ++++++ core/js/tests/specs/setupchecksSpec.js | 37 ++++++++++++++++++ settings/Controller/CheckSetupController.php | 39 +++++++++++++++++++ .../Controller/CheckSetupControllerTest.php | 12 +++++- 4 files changed, 99 insertions(+), 1 deletion(-) diff --git a/core/js/setupchecks.js b/core/js/setupchecks.js index 4d2097a5b5..fcbbba6af6 100644 --- a/core/js/setupchecks.js +++ b/core/js/setupchecks.js @@ -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. For better performance we recommend ↗ to use following settings in the php.ini:', + { + docLink: data.phpOpcacheDocumentation, + } + ) + "
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
", + type: OC.SetupChecks.MESSAGE_TYPE_INFO + }); + } } else { messages.push({ msg: t('core', 'Error occurred while checking server setup'), diff --git a/core/js/tests/specs/setupchecksSpec.js b/core/js/tests/specs/setupchecksSpec.js index faa8a2bf27..1ee16a7af8 100644 --- a/core/js/tests/specs/setupchecksSpec.js +++ b/core/js/tests/specs/setupchecksSpec.js @@ -155,6 +155,7 @@ describe('OC.SetupChecks tests', function() { forwardedForHeadersWorking: true, isCorrectMemcachedPHPModuleInstalled: true, hasPassedCodeIntegrityCheck: true, + isOpcacheProperlySetup: true, }) ); @@ -186,6 +187,7 @@ describe('OC.SetupChecks tests', function() { forwardedForHeadersWorking: true, isCorrectMemcachedPHPModuleInstalled: true, hasPassedCodeIntegrityCheck: true, + isOpcacheProperlySetup: true, }) ); @@ -218,6 +220,7 @@ describe('OC.SetupChecks tests', function() { forwardedForHeadersWorking: true, isCorrectMemcachedPHPModuleInstalled: true, hasPassedCodeIntegrityCheck: true, + isOpcacheProperlySetup: true, }) ); @@ -248,6 +251,7 @@ describe('OC.SetupChecks tests', function() { forwardedForHeadersWorking: true, isCorrectMemcachedPHPModuleInstalled: true, hasPassedCodeIntegrityCheck: true, + isOpcacheProperlySetup: true, }) ); @@ -276,6 +280,7 @@ describe('OC.SetupChecks tests', function() { forwardedForHeadersWorking: true, isCorrectMemcachedPHPModuleInstalled: false, hasPassedCodeIntegrityCheck: true, + isOpcacheProperlySetup: true, }) ); @@ -304,6 +309,7 @@ describe('OC.SetupChecks tests', function() { reverseProxyDocs: 'https://docs.owncloud.org/foo/bar.html', isCorrectMemcachedPHPModuleInstalled: true, hasPassedCodeIntegrityCheck: true, + isOpcacheProperlySetup: true, }) ); @@ -353,6 +359,7 @@ describe('OC.SetupChecks tests', function() { phpSupported: {eol: true, version: '5.4.0'}, isCorrectMemcachedPHPModuleInstalled: true, hasPassedCodeIntegrityCheck: true, + isOpcacheProperlySetup: true, }) ); @@ -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. For better performance we recommend ↗ to use following settings in the php.ini:' + "
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
", + type: OC.SetupChecks.MESSAGE_TYPE_INFO + }]); + done(); + }); + }); }); describe('checkGeneric', function() { diff --git a/settings/Controller/CheckSetupController.php b/settings/Controller/CheckSetupController.php index d9e4846672..016f6a1dab 100644 --- a/settings/Controller/CheckSetupController.php +++ b/settings/Controller/CheckSetupController.php @@ -26,6 +26,7 @@ namespace OC\Settings\Controller; +use bantu\IniGetWrapper\IniGetWrapper; use GuzzleHttp\Exception\ClientException; use OC\AppFramework\Http; use OC\IntegrityCheck\Checker; @@ -354,6 +355,42 @@ Raw output 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 */ @@ -372,6 +409,8 @@ Raw output 'isCorrectMemcachedPHPModuleInstalled' => $this->isCorrectMemcachedPHPModuleInstalled(), 'hasPassedCodeIntegrityCheck' => $this->checker->hasPassedCheck(), 'codeIntegrityCheckerDocumentation' => $this->urlGenerator->linkToDocs('admin-code-integrity'), + 'isOpcacheProperlySetup' => $this->isOpcacheProperlySetup(), + 'phpOpcacheDocumentation' => $this->urlGenerator->linkToDocs('admin-php-opcache'), ] ); } diff --git a/tests/Settings/Controller/CheckSetupControllerTest.php b/tests/Settings/Controller/CheckSetupControllerTest.php index f087fec210..e600f7e5e9 100644 --- a/tests/Settings/Controller/CheckSetupControllerTest.php +++ b/tests/Settings/Controller/CheckSetupControllerTest.php @@ -311,6 +311,14 @@ class CheckSetupControllerTest extends TestCase { ->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'); + $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( [ @@ -328,7 +336,9 @@ class CheckSetupControllerTest extends TestCase { '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());