After further testing I found that a simple preg_match() search is also faster than exploding something.
0.0014879703521729 explode
0.0012550354003906 preg
0.054396152496338 glob
<?php
for($i=0; $i<20; $i++) {
print ' ';
}
$start_time = time()+microtime(true);
ob_start();
for($x=0; $x < 10; $x++) {
//glob() is much slower so we use opendir...
foreach(array('cache/', 'cache/') as $dir) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if(end(explode('.', $file)) == 'php') {
//Include the file
require_once($dir. $file);
//Update the array of files included
$site_config["included_files"][$file] = filesize($file);
} else {
print $dir. ' '. $file. '<br />';
}
}
closedir($dh);
} else {
die('<h2>Error!</h2<p>Couldn\'t load '. $dir. '</p>');
}
}
}
ob_end_clean();
print ((time()+microtime(true)) - $start_time). ' explode <br />';
$start_time = time()+microtime(true);
ob_start();
for($x=0; $x < 20; $x++) {
//glob() is much slower so we use opendir...
foreach(array('cache/', 'cache/') as $dir) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if(preg_match("/.php/", $file)) {
//Include the file
require_once($dir. $file);
//Update the array of files included
$site_config["included_files"][$file] = filesize($file);
} else {
print $dir. ' '. $file. '<br />';
}
}
closedir($dh);
} else {
die('<h2>Error!</h2<p>Couldn\'t load '. $dir. '</p>');
}
}
}
ob_end_clean();
print ((time()+microtime(true)) - $start_time). ' preg <br />';
$start_time = time()+microtime(true);
ob_start();
for($x=0; $x < 20; $x++) {
//Include the function files
foreach (glob("cache/*.html") as $file) {
//Include the file
include($file);
//$value = rand(0, 10000) * 2345678;
}
}
ob_end_clean();
print ((time()+microtime(true)) - $start_time). ' glob <br />';
?>