preload
This commit is contained in:
@@ -211,6 +211,7 @@ module.exports = function (grunt) {
|
||||
'daemon.php',
|
||||
'rebuild.php',
|
||||
'clear_cache.php',
|
||||
'preload.php',
|
||||
'upgrade.php',
|
||||
'extension.php',
|
||||
'websocket.php',
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2020 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\ApplicationRunners;
|
||||
|
||||
use Espo\Core\{
|
||||
Utils\Preload as PreloadUtil,
|
||||
};
|
||||
|
||||
/**
|
||||
* Runs a preload.
|
||||
*
|
||||
* @see https://www.php.net/manual/en/opcache.preloading.php
|
||||
*/
|
||||
class Preload implements ApplicationRunner
|
||||
{
|
||||
use Cli;
|
||||
|
||||
public function run()
|
||||
{
|
||||
$preload = new PreloadUtil();
|
||||
$preload->process();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2020 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Utils;
|
||||
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
use RegexIterator;
|
||||
use RecursiveRegexIterator;
|
||||
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Scans all PHP files and loads them. Used for a preloading.
|
||||
*
|
||||
* @see https://www.php.net/manual/en/opcache.preloading.php
|
||||
*/
|
||||
class Preload
|
||||
{
|
||||
protected $dirList = [
|
||||
'application',
|
||||
'vendor/slim',
|
||||
'vendor/nikic/fast-route',
|
||||
];
|
||||
|
||||
private $counter = 0;
|
||||
|
||||
protected $ignoreList = [
|
||||
'application/Espo/Core/Mail/Parsers/PhpMimeMailParser/',
|
||||
'vendor/nikic/fast-route/test',
|
||||
];
|
||||
|
||||
public function process()
|
||||
{
|
||||
foreach ($this->dirList as $dir) {
|
||||
$this->processForDir($dir);
|
||||
}
|
||||
|
||||
echo "Success." . PHP_EOL;
|
||||
echo "Files preloaded: " . (string) $this->counter . "." . PHP_EOL;
|
||||
}
|
||||
|
||||
protected function processForDir(string $dir)
|
||||
{
|
||||
$directory = new RecursiveDirectoryIterator($dir);
|
||||
$fullTree = new RecursiveIteratorIterator($directory);
|
||||
$phpFiles = new RegexIterator($fullTree, '/.+((?<!Test)+\.php$)/i', RecursiveRegexIterator::GET_MATCH);
|
||||
|
||||
foreach ($phpFiles as $key => $file) {
|
||||
$this->processFile($file[0]);
|
||||
}
|
||||
}
|
||||
|
||||
protected function processFile(string $file)
|
||||
{
|
||||
if ($this->isFileToBeIgnored($file)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
require_once($file);
|
||||
|
||||
$this->counter ++;
|
||||
}
|
||||
catch (Throwable $e) {
|
||||
$this->processException($e);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
protected function processException(Throwable $e)
|
||||
{
|
||||
echo "Error occured." . PHP_EOL;
|
||||
|
||||
$msg = $e->getMessage();
|
||||
|
||||
if ($msg) {
|
||||
echo "Message: {$msg}" . PHP_EOL;
|
||||
}
|
||||
|
||||
$file = $e->getFile();
|
||||
|
||||
if ($file) {
|
||||
echo "File: {$file}" . PHP_EOL;
|
||||
}
|
||||
|
||||
echo "Line: " . $e->getLine() . PHP_EOL;
|
||||
}
|
||||
|
||||
protected function isFileToBeIgnored(string $file) : bool
|
||||
{
|
||||
$file = str_replace('\\', '/', $file);
|
||||
|
||||
foreach ($this->ignoreList as $item) {
|
||||
if (strpos($file, $item) === 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
return in_array($file, $this->ignoreList);
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2020 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
/**
|
||||
* Preloads PHP files. Can be also used to check the syntax.
|
||||
*
|
||||
* @see https://www.php.net/manual/en/opcache.preloading.php
|
||||
*
|
||||
* Important: Preloading must be disabled before upgrading and extension installation.
|
||||
*/
|
||||
|
||||
include "bootstrap.php";
|
||||
|
||||
use Espo\Core\{
|
||||
Application,
|
||||
ApplicationRunners\Preload,
|
||||
};
|
||||
|
||||
(new Application())->run(Preload::class);
|
||||
Reference in New Issue
Block a user