ElkArte Community

General => Chit Chat => Topic started by: badmonkey on February 08, 2020, 02:21:11 am

Title: php7.4 preloading
Post by: badmonkey on February 08, 2020, 02:21:11 am
Is anyone using php7.4? Are you using preloading for elk? I'm interested in experimenting with preloading. Knowledge to pull it off is lacking. Apparently the initiation script must include an array of all php files in the script (here, elk) as well as appropriate classes and namespaces. Seems it may be a daunting task for the uh, lesser codeworthy. How difficult would this be?
Title: Re: php7.4 preloading
Post by: ahrasis on February 08, 2020, 03:37:02 am
Is anyone using php7.4?
Yes.
Are you using preloading for elk?
Nope.
How difficult would this be?
Not sure. Haven't tried it yet.
Title: Re: php7.4 preloading
Post by: emanuele on February 13, 2020, 08:29:40 pm
Interesting.
Well, the "quick&dirty" way would be to take any file in sources, themes and the root and require_once all of them.
Only thing to pay attention should be the order to avoid issues, but if you start instantiating the bootstrap class and loading the autoloader, that should do most of the work.
It may be something like:
Code: [Select]
<?php

$forum_path = '/path/to/forum';
$root_files = [
'index.php',
'bootstrap.php',
'email_imap_cron.php',
'emailpost.php',
'emailtopic.php',
'ssi_examples.php',
'SSI.php',
'subscriptions.php'
];

function getFilesRecursive($dir, $ext = '.php')
{
$full_paths = array();

$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST,
RecursiveIteratorIterator::CATCH_GET_CHILD
);
$filter = new RegexIterator($iterator, '/' . preg_quote($ext) . '$/');

foreach ($filter as $path => $file)
{
if ($file->isDir() === false)
{
$full_paths[] = $path;
}
}

return $full_paths;
}

require_once($forum_path . '/bootstrap.php');
$source_files = getFilesRecursive($forum_path . '/sources');
$themes_files = getFilesRecursive($forum_path . '/themes');
foreach ($root_files as $k => $file)
{
$root_files[$k] = $forum_path . '/' . $root_files[$k];
}

foreach ([$source_files, $themes_files, $root_files] as $files)
{
foreach ($files as $file)
{
require_once($file);
}
}

No idea if it works or not.