Re: How expensive is glob'ing a dir and including all the files? [message #179142 is a reply to message #179140] |
Fri, 14 September 2012 19:44 |
Salvatore
Messages: 38 Registered: September 2012
Karma:
|
Member |
|
|
On 2012-09-14, J. Frank Parnell <juglesh(at)gmail(dot)com> wrote:
> I have my 'funcs' dir, full of about 120 files, totaling ~800KB. A
> bunch of little utility functions. Here is basically how i include them:
> <?php
> if ((file_exists($funccache)) AND (@$_GET['recache']!=true)){
> include $funccache;//just an array of the files names, see below.
> }else{
> $incs = glob($funcspath."*.php") ;
> $ra = var_export($incs,true);
> $put = @file_put_contents($funccache,"<?php \$incs = $ra; ?>");
> }
> foreach ($incs as $i) {
> require $i;
> }
> ?>
>
> So, my question is, am I saving a significant amount of ram/cpu/time by
> keeping this cache of filenames or should I just glob the dir and
> include what's in there everytime?
You're only making your script unnecessarily complicated. Just use the
include() function to only include the functions you need.
If you have performance issues -- which you shouldn't -- consider
installing a PHP accelerator.
--
Blah blah bleh...
GCS/CM d(-)@>-- s+:- !a C++$ UBL++++$ L+$ W+++$ w M++ Y++ b++
|
|
|