Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #7068 > unrolled thread

How expensive is glob'ing a dir and including all the files?

Started by"J. Frank Parnell" <juglesh@gmail.com>
First post2012-09-14 12:35 -0700
Last post2012-09-16 17:46 -0400
Articles 20 on this page of 27 — 8 participants

Back to article view | Back to comp.lang.php


Contents

  How expensive is glob'ing a dir and including all the files? "J. Frank Parnell" <juglesh@gmail.com> - 2012-09-14 12:35 -0700
    Re: How expensive is glob'ing a dir and including all the files? Eli the Bearded <*@eli.users.panix.com> - 2012-09-14 19:41 +0000
      Re: How expensive is glob'ing a dir and including all the files? "J. Frank Parnell" <juglesh@gmail.com> - 2012-09-14 15:24 -0700
        Re: How expensive is glob'ing a dir and including all the files? Jerry Stuckle <jstucklex@attglobal.net> - 2012-09-14 19:24 -0400
          Re: How expensive is glob'ing a dir and including all the files? Michael Fesser <netizen@gmx.de> - 2012-09-15 01:43 +0200
            Re: How expensive is glob'ing a dir and including all the files? Jerry Stuckle <jstucklex@attglobal.net> - 2012-09-14 21:45 -0400
              Re: How expensive is glob'ing a dir and including all the files? "J. Frank Parnell" <juglesh@gmail.com> - 2012-09-16 10:50 -0700
                Re: How expensive is glob'ing a dir and including all the files? Jerry Stuckle <jstucklex@attglobal.net> - 2012-09-16 17:45 -0400
                  Re: How expensive is glob'ing a dir and including all the files? "J. Frank Parnell" <juglesh@gmail.com> - 2012-09-16 16:00 -0700
                    Re: How expensive is glob'ing a dir and including all the files? Jerry Stuckle <jstucklex@attglobal.net> - 2012-09-16 20:17 -0400
    Re: How expensive is glob'ing a dir and including all the files? Salvatore <sal@yojimbo.hack.invalid> - 2012-09-14 19:44 +0000
    Re: How expensive is glob'ing a dir and including all the files? Anders Wegge Keller <wegge@wegge.dk> - 2012-09-15 08:08 +0200
      Re: How expensive is glob'ing a dir and including all the files? Jerry Stuckle <jstucklex@attglobal.net> - 2012-09-15 09:14 -0400
        Re: How expensive is glob'ing a dir and including all the files? Anders Wegge Keller <wegge@wegge.dk> - 2012-09-15 23:41 +0200
          Re: How expensive is glob'ing a dir and including all the files? Jerry Stuckle <jstucklex@attglobal.net> - 2012-09-15 18:06 -0400
            Re: How expensive is glob'ing a dir and including all the files? Anders Wegge Keller <wegge@wegge.dk> - 2012-09-16 00:10 +0200
              Re: How expensive is glob'ing a dir and including all the files? Jerry Stuckle <jstucklex@attglobal.net> - 2012-09-15 18:21 -0400
                Re: How expensive is glob'ing a dir and including all the files? Anders Wegge Keller <wegge@wegge.dk> - 2012-09-16 00:39 +0200
                  Re: How expensive is glob'ing a dir and including all the files? Jerry Stuckle <jstucklex@attglobal.net> - 2012-09-15 18:45 -0400
                    Re: How expensive is glob'ing a dir and including all the files? Anders Wegge Keller <wegge@wegge.dk> - 2012-09-16 00:59 +0200
                      Re: How expensive is glob'ing a dir and including all the files? The Natural Philosopher <tnp@invalid.invalid> - 2012-09-16 00:09 +0100
                      Re: How expensive is glob'ing a dir and including all the files? Jerry Stuckle <jstucklex@attglobal.net> - 2012-09-15 19:19 -0400
                      Re: How expensive is glob'ing a dir and including all the files? Jerry Stuckle <jstucklex@attglobal.net> - 2012-09-15 19:27 -0400
              Re: How expensive is glob'ing a dir and including all the files? The Natural Philosopher <tnp@invalid.invalid> - 2012-09-15 23:38 +0100
          Re: How expensive is glob'ing a dir and including all the files? "Peter H. Coffin" <hellsop@ninehells.com> - 2012-09-16 09:37 -0500
            Re: How expensive is glob'ing a dir and including all the files? Anders Wegge Keller <wegge@wegge.dk> - 2012-09-16 17:32 +0200
              Re: How expensive is glob'ing a dir and including all the files? Jerry Stuckle <jstucklex@attglobal.net> - 2012-09-16 17:46 -0400

Page 1 of 2  [1] 2  Next page →


#7068 — How expensive is glob'ing a dir and including all the files?

From"J. Frank Parnell" <juglesh@gmail.com>
Date2012-09-14 12:35 -0700
SubjectHow expensive is glob'ing a dir and including all the files?
Message-ID<38015b6a-5ef2-4f92-9aa2-6eea01c7097a@googlegroups.com>
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?

[toc] | [next] | [standalone]


#7069

FromEli the Bearded <*@eli.users.panix.com>
Date2012-09-14 19:41 +0000
Message-ID<eli$1209141539@qz.little-neck.ny.us>
In reply to#7068
In comp.lang.php, J. Frank Parnell <juglesh@gmail.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:
...
> 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?

The glob for a directory with 120 files will be nothing compared to
the time it takes php to include() 800KB worth of stuff. You might
want to consider only including what you really need. That will be
the bigger win.

Elijah
------
glob on a very big directory (multiple thousands of files) is different

[toc] | [prev] | [next] | [standalone]


#7071

From"J. Frank Parnell" <juglesh@gmail.com>
Date2012-09-14 15:24 -0700
Message-ID<ec8ecf2a-45eb-406b-b0f8-29c4dda0a536@googlegroups.com>
In reply to#7069
On Friday, September 14, 2012 12:41:35 PM UTC-7, Eli the Bearded wrote:
> In comp.lang.php, J. Frank Parnell <> 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:
> 
> ...
> 
> > 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?
> 
> 
> The glob for a directory with 120 files will be nothing compared to
> the time it takes php to include() 800KB worth of stuff. You might 
> want to consider only including what you really need. That will be 
> the bigger win.
> --- 
> glob on a very big directory (multiple thousands of files) is different

When I do properties locally, on Win, it says size: 408KB, size on disc: 720KB.  Compared to the wordpress 'includes' dir at 5Megs, doesnt seem like much, although i'm not sure if wp includes that whole dir, always.  Would it be more efficient to concatenate my include files?

[toc] | [prev] | [next] | [standalone]


#7072

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-09-14 19:24 -0400
Message-ID<k30eco$3s1$1@dont-email.me>
In reply to#7071
On 9/14/2012 6:24 PM, J. Frank Parnell wrote:
> On Friday, September 14, 2012 12:41:35 PM UTC-7, Eli the Bearded wrote:
>> In comp.lang.php, J. Frank Parnell <> 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:
>>
>> ...
>>
>>> 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?
>>
>>
>> The glob for a directory with 120 files will be nothing compared to
>> the time it takes php to include() 800KB worth of stuff. You might
>> want to consider only including what you really need. That will be
>> the bigger win.
>> ---
>> glob on a very big directory (multiple thousands of files) is different
>
> When I do properties locally, on Win, it says size: 408KB, size on disc: 720KB.  Compared to the wordpress 'includes' dir at 5Megs, doesnt seem like much, although i'm not sure if wp includes that whole dir, always.  Would it be more efficient to concatenate my include files?
>

As others have said - include only what you need.  The time consuming 
part is parsing the PHP code, not reading one or more files. 
Concatenating will still require PHP to parse the code.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#7073

FromMichael Fesser <netizen@gmx.de>
Date2012-09-15 01:43 +0200
Message-ID<bnf758hpb7pbpvo6mijhq57ga9qq8366pr@mfesser.de>
In reply to#7072
.oO(Jerry Stuckle)

>On 9/14/2012 6:24 PM, J. Frank Parnell wrote:
>
>>When I do properties locally, on Win, it says size: 408KB, size on disc:
>>720KB.  Compared to the wordpress 'includes' dir at 5Megs, doesnt seem
>>like much, although i'm not sure if wp includes that whole dir, always. 
>>Would it be more efficient to concatenate my include files?
>
>As others have said - include only what you need.  The time consuming 
>part is parsing the PHP code, not reading one or more files. 
>Concatenating will still require PHP to parse the code.

Sure, but it makes a difference if you include a hundred files, each
with a single function, or if you just include a single file containing
all those functions.

It would make sense to group all the functions into semantic units and
put these into single files or classes. Then include the units you need.

Micha

-- 
http://mfesser.de/
Fotos | Blog | Flohmarkt

[toc] | [prev] | [next] | [standalone]


#7074

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-09-14 21:45 -0400
Message-ID<k30mju$9g3$1@dont-email.me>
In reply to#7073
On 9/14/2012 7:43 PM, Michael Fesser wrote:
> .oO(Jerry Stuckle)
>
>> On 9/14/2012 6:24 PM, J. Frank Parnell wrote:
>>
>>> When I do properties locally, on Win, it says size: 408KB, size on disc:
>>> 720KB.  Compared to the wordpress 'includes' dir at 5Megs, doesnt seem
>>> like much, although i'm not sure if wp includes that whole dir, always.
>>> Would it be more efficient to concatenate my include files?
>>
>> As others have said - include only what you need.  The time consuming
>> part is parsing the PHP code, not reading one or more files.
>> Concatenating will still require PHP to parse the code.
>
> Sure, but it makes a difference if you include a hundred files, each
> with a single function, or if you just include a single file containing
> all those functions.
>
> It would make sense to group all the functions into semantic units and
> put these into single files or classes. Then include the units you need.
>
> Micha
>

Not that much difference.  The majority of the time is in the parsing, 
not reading the files, especially since the files will most probably 
already be in buffers.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#7090

From"J. Frank Parnell" <juglesh@gmail.com>
Date2012-09-16 10:50 -0700
Message-ID<dcd7e8d6-7e45-4b86-b624-376bf818feba@googlegroups.com>
In reply to#7074
Ok, so I tested via:
function microtime_float(){
    list($utime, $time) = explode(" ", microtime());
    return ((float)$utime + (float)$time);
}
$script_start = microtime_float();
	require '_funcs/_funcs.php';//this file does the globing, cacheing, including
$script_end = microtime_float();
echo "Script executed in ".bcsub($script_end, $script_start, 4)." seconds." ;

and I got
Script executed in 0.0200 seconds
Thats with either globing or reading the cache file (which backs up the statement that the glob doesnt add much)

Afa size and traffic of sites, wordpress sites, plenty of plugins and custom stuff. Traffic, some might be 100-500 page views/day.

Testing script execution for the whole page gave me around 2.5 seconds.

The whole front page takes around 2 seconds
On Friday, September 14, 2012 6:45:35 PM UTC-7, Jerry Stuckle wrote:
> On 9/14/2012 7:43 PM, Michael Fesser wrote:
> > .oO(Jerry Stuckle)
> >> On 9/14/2012 6:24 PM, J. Frank Parnell wrote:
> >>> When I do properties locally, on Win, it says size: 408KB, size on disc:
> >>> 720KB.  Compared to the wordpress 'includes' dir at 5Megs, doesnt seem
> >>> like much, although i'm not sure if wp includes that whole dir, always.
> >>> Would it be more efficient to concatenate my include files?
> >> As others have said - include only what you need.  The time consuming
> >> part is parsing the PHP code, not reading one or more files.
> Not that much difference.  The majority of the time is in the parsing, 
> not reading the files, especially since the files will most probably 
> already be in buffers.
> 

[toc] | [prev] | [next] | [standalone]


#7091

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-09-16 17:45 -0400
Message-ID<k35ha4$bo2$1@dont-email.me>
In reply to#7090
On 9/16/2012 1:50 PM, J. Frank Parnell wrote:
> Ok, so I tested via:
> function microtime_float(){
>      list($utime, $time) = explode(" ", microtime());
>      return ((float)$utime + (float)$time);
> }
> $script_start = microtime_float();
> 	require '_funcs/_funcs.php';//this file does the globing, cacheing, including
> $script_end = microtime_float();
> echo "Script executed in ".bcsub($script_end, $script_start, 4)." seconds." ;
>
> and I got
> Script executed in 0.0200 seconds
> Thats with either globing or reading the cache file (which backs up the statement that the glob doesnt add much)
>

That's a HUGE amount of server time!

> Afa size and traffic of sites, wordpress sites, plenty of plugins and custom stuff. Traffic, some might be 100-500 page views/day.
>
> Testing script execution for the whole page gave me around 2.5 seconds.
>

Even worse!

> The whole front page takes around 2 seconds

Not good at all.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#7093

From"J. Frank Parnell" <juglesh@gmail.com>
Date2012-09-16 16:00 -0700
Message-ID<7fd73583-9e50-4b8c-858a-a839bcdeffb4@googlegroups.com>
In reply to#7091
On Sunday, September 16, 2012 2:45:40 PM UTC-7, Jerry Stuckle wrote:
> On 9/16/2012 1:50 PM, J. Frank Parnell wrote:
> 
> > Ok, so I tested 
> > and I got 
> > Script executed in 0.0200 seconds 
> > Thats with either globing or reading the cache file (which backs up the statement that the glob doesnt add much)
> 
> That's a HUGE amount of server time!

> > Afa size and traffic of sites, wordpress sites, plenty of plugins and custom stuff. Traffic, some might be 100-500 page views/day.
> > Testing script execution for the whole page gave me around 2.5 seconds. 
> Even worse!
> > The whole front page takes around 2 seconds
> Not good at all.

Another wp site, but without several facebook curls was .3 seconds (homepage), another .7, and a non wp site of mine, but still using my funcs includer was .03 seconds.

What do you think a good average should be, for a db driven site?

[toc] | [prev] | [next] | [standalone]


#7094

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-09-16 20:17 -0400
Message-ID<k35q81$tso$1@dont-email.me>
In reply to#7093
On 9/16/2012 7:00 PM, J. Frank Parnell wrote:
> On Sunday, September 16, 2012 2:45:40 PM UTC-7, Jerry Stuckle wrote:
>> On 9/16/2012 1:50 PM, J. Frank Parnell wrote:
>>
>>> Ok, so I tested
>>> and I got
>>> Script executed in 0.0200 seconds
>>> Thats with either globing or reading the cache file (which backs up the statement that the glob doesnt add much)
>>
>> That's a HUGE amount of server time!
>
>>> Afa size and traffic of sites, wordpress sites, plenty of plugins and custom stuff. Traffic, some might be 100-500 page views/day.
>>> Testing script execution for the whole page gave me around 2.5 seconds.
>> Even worse!
>>> The whole front page takes around 2 seconds
>> Not good at all.
>
> Another wp site, but without several facebook curls was .3 seconds (homepage), another .7, and a non wp site of mine, but still using my funcs includer was .03 seconds.
>
> What do you think a good average should be, for a db driven site?
>

Gawd, that's terrible!

Most of mine come in at under 0.001 seconds to server a page.  A few run 
a bit more, but not much.

I'm surprised shared hosting allows you to take that much CPU time.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#7070

FromSalvatore <sal@yojimbo.hack.invalid>
Date2012-09-14 19:44 +0000
Message-ID<k301f5$1p2f$1@yojimbo.hack>
In reply to#7068
On 2012-09-14, J. Frank Parnell <juglesh@gmail.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++

[toc] | [prev] | [next] | [standalone]


#7075

FromAnders Wegge Keller <wegge@wegge.dk>
Date2012-09-15 08:08 +0200
Message-ID<87mx0rddit.fsf@huddi.jernurt.dk>
In reply to#7068
"J. Frank Parnell" <juglesh@gmail.com> writes:

> 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 may want to consider autoloading classes as needed. See
http://php.net/manual/en/language.oop5.autoload.php

 This approach is of course dependent on using PHP5 *and* having an
OO design. 

-- 
/Wegge

Leder efter redundant peering af dk.*,linux.debian.*

[toc] | [prev] | [next] | [standalone]


#7076

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-09-15 09:14 -0400
Message-ID<k31uvt$8b0$1@dont-email.me>
In reply to#7075
On 9/15/2012 2:08 AM, Anders Wegge Keller wrote:
> "J. Frank Parnell" <juglesh@gmail.com> writes:
>
>> 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 may want to consider autoloading classes as needed. See
> http://php.net/manual/en/language.oop5.autoload.php
>
>   This approach is of course dependent on using PHP5 *and* having an
> OO design.
>

Additionally, you're never sure which module you got.  All kinds of 
hard-to-diagnose things can happen when someone uploads a module of the 
same name but earlier in the search path.  You'll be trying to debug one 
module while the system is using an entirely different module.

Plus the extra overhead of searching for the module, of course.

This is not a feature I recommend.  It can cause many problems, and good 
programming techniques render it pretty much unnecessary.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#7077

FromAnders Wegge Keller <wegge@wegge.dk>
Date2012-09-15 23:41 +0200
Message-ID<87haqzc6bl.fsf@huddi.jernurt.dk>
In reply to#7076
Jerry Stuckle <jstucklex@attglobal.net> writes:

> On 9/15/2012 2:08 AM, Anders Wegge Keller wrote:
> > "J. Frank Parnell" <juglesh@gmail.com> writes:
> >
> >> 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 may want to consider autoloading classes as needed. See
> > http://php.net/manual/en/language.oop5.autoload.php
> >
> >   This approach is of course dependent on using PHP5 *and* having an
> > OO design.
> >
> 
> Additionally, you're never sure which module you got. 

 Speaking from experience?

> All kinds of hard-to-diagnose things can happen when someone uploads
> a module of the same name but earlier in the search path.

 You let "someone" muck around with your code? Are you hosting at
GoDaddy or something like that?

>  You'll be trying to debug one module while the system is using an
> entirely different module.

 Only if you haven't got a clue...
 
> Plus the extra overhead of searching for the module, of course.

 Surely, you are jesting. Or should I ask "Once unwitting, twice shy"?

> This is not a feature I recommend.  It can cause many problems, and
> good programming techniques render it pretty much unnecessary.

 I don't expect you to recognize a metric ton of clue, landing on your
head, but for the record let me tell the rest of the audience what the
self-proclaimed king of c.l.p is not smart enough to fiure out.

 Wait for it...

 Wait a bit more ...


 The autoloader can be overridden by whatever code you care to call
when there is a request for an unknown class <rimshot />

[Simplified code ahead]

{classloader.php}

global $clClassMap;

$clClassMap = array(
		    /* Interfaces */
		    'iArticle' => 'classes/articleinterface.php',

		    /* Base classes */
		    'Page' => 'classes/pageobj.php',
		    'Request' => 'classes/request.php',

                    ... <<The rest of whatever classes defined>>

		    );


class AutoLoader {
  static function autoload ($classname) {
    global $clClassMap;

    $filename = false;

    if ( isset ( $clClassMap[$classname] ) ) {
      $filename=$clClassMap[$classname]
      require("${ABSROOT}/${filename}");
    } else {
      return false; /* And throw an error. */
    }
}

if ( function_exists ( 'spl_autoload_register' ) ) {
  spl_autoload_register ( array('AutoLoader', 'autoload') );
} else {
  function __autoload( $class ) {
    AutoLoader::autoload( $class );
  }
  
  ini_set( 'unserialize_callback_func', '__autoload' );
}

{END classloader.php}

 Everywhere else, require classloader.php, and use whatever classe you
want to. In case you forget to add them to $clClassMap, even Jerry
Stuckle should be smart enough to get what the error means. At least
after a few false starts. Also note that there is no noticable
overhead looking up an entry in a already-loaded array, compared to
the amortized overhead of the Stuckle-approved method of including and
parsing everything that has a remote chance of being relevant.

 There might be a typo or two in the preceeding code. After all, it's
a simplified example. But I expect the majority of this group to be
able to work out the syntax errors. If not, please ask for
clarification.

-- 
/Wegge

Leder efter redundant peering af dk.*,linux.debian.*

[toc] | [prev] | [next] | [standalone]


#7078

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-09-15 18:06 -0400
Message-ID<k32u4s$h3j$1@dont-email.me>
In reply to#7077
On 9/15/2012 5:41 PM, Anders Wegge Keller wrote:
> Jerry Stuckle <jstucklex@attglobal.net> writes:
>
>> On 9/15/2012 2:08 AM, Anders Wegge Keller wrote:
>>> "J. Frank Parnell" <juglesh@gmail.com> writes:
>>>
>>>> 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 may want to consider autoloading classes as needed. See
>>> http://php.net/manual/en/language.oop5.autoload.php
>>>
>>>    This approach is of course dependent on using PHP5 *and* having an
>>> OO design.
>>>
>>
>> Additionally, you're never sure which module you got.
>
>   Speaking from experience?
>

Not personally, but I've seen it happen to others.

>> All kinds of hard-to-diagnose things can happen when someone uploads
>> a module of the same name but earlier in the search path.
>
>   You let "someone" muck around with your code? Are you hosting at
> GoDaddy or something like that?
>

Nope, but I'm not necessarily the only developer on a project, nor am I 
necessarily the only one who will ever work on the project.  In fact, 
chances are I will not be.  I don't work on 5 page hobby sites.

>>   You'll be trying to debug one module while the system is using an
>> entirely different module.
>
>   Only if you haven't got a clue...
>

Which you don't...

>> Plus the extra overhead of searching for the module, of course.
>
>   Surely, you are jesting. Or should I ask "Once unwitting, twice shy"?
>

Nope, it can take significant amount of time - I've seen some long paths 
in the auto append.

>> This is not a feature I recommend.  It can cause many problems, and
>> good programming techniques render it pretty much unnecessary.
>
>   I don't expect you to recognize a metric ton of clue, landing on your
> head, but for the record let me tell the rest of the audience what the
> self-proclaimed king of c.l.p is not smart enough to fiure out.
>
>   Wait for it...
>
>   Wait a bit more ...
>
>
>   The autoloader can be overridden by whatever code you care to call
> when there is a request for an unknown class <rimshot />
>
> [Simplified code ahead]
>
> {classloader.php}
>
> global $clClassMap;
>
> $clClassMap = array(
> 		    /* Interfaces */
> 		    'iArticle' => 'classes/articleinterface.php',
>
> 		    /* Base classes */
> 		    'Page' => 'classes/pageobj.php',
> 		    'Request' => 'classes/request.php',
>
>                      ... <<The rest of whatever classes defined>>
>
> 		    );
>
>
> class AutoLoader {
>    static function autoload ($classname) {
>      global $clClassMap;
>
>      $filename = false;
>
>      if ( isset ( $clClassMap[$classname] ) ) {
>        $filename=$clClassMap[$classname]
>        require("${ABSROOT}/${filename}");
>      } else {
>        return false; /* And throw an error. */
>      }
> }
>
> if ( function_exists ( 'spl_autoload_register' ) ) {
>    spl_autoload_register ( array('AutoLoader', 'autoload') );
> } else {
>    function __autoload( $class ) {
>      AutoLoader::autoload( $class );
>    }
>
>    ini_set( 'unserialize_callback_func', '__autoload' );
> }
>
> {END classloader.php}
>
>   Everywhere else, require classloader.php, and use whatever classe you
> want to. In case you forget to add them to $clClassMap, even Jerry
> Stuckle should be smart enough to get what the error means. At least
> after a few false starts. Also note that there is no noticable
> overhead looking up an entry in a already-loaded array, compared to
> the amortized overhead of the Stuckle-approved method of including and
> parsing everything that has a remote chance of being relevant.
>
>   There might be a typo or two in the preceeding code. After all, it's
> a simplified example. But I expect the majority of this group to be
> able to work out the syntax errors. If not, please ask for
> clarification.
>

Sure, which means the interpreter has to load and parse even more code 
unnecessarily. And there is no such thing as an "already-loaded array" - 
every invocation of a script starts fresh.

But then we all know when you only work on 5 page sites which receive 
100 page views/day, you can get away with this.  But we know you'd never 
be able to handle a decent sized site.


-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#7079

FromAnders Wegge Keller <wegge@wegge.dk>
Date2012-09-16 00:10 +0200
Message-ID<878vcbc4yk.fsf@huddi.jernurt.dk>
In reply to#7078
Jerry Stuckle <jstucklex@attglobal.net> writes:

> But then we all know when you only work on 5 page sites which
> receive 100 page views/day, you can get away with this.  But we know
> you'd never be able to handle a decent sized site.

 You are too easy. Code similar to this is the central part of
Mediawiki, the software that runs this small 100-hits/day-site, called
wikipedia.

 Go get a new book of insults. The one you use is clearly outdated,
just as your grasp of reality, good coding practices for the 21st
century and project managing.

-- 
/Wegge

Leder efter redundant peering af dk.*,linux.debian.*

[toc] | [prev] | [next] | [standalone]


#7080

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-09-15 18:21 -0400
Message-ID<k32v1a$l30$1@dont-email.me>
In reply to#7079
On 9/15/2012 6:10 PM, Anders Wegge Keller wrote:
> Jerry Stuckle <jstucklex@attglobal.net> writes:
>
>> But then we all know when you only work on 5 page sites which
>> receive 100 page views/day, you can get away with this.  But we know
>> you'd never be able to handle a decent sized site.
>
>   You are too easy. Code similar to this is the central part of
> Mediawiki, the software that runs this small 100-hits/day-site, called
> wikipedia.
>

Sure - and look how many servers they need to run Mediawiki.  Or are you 
trying to claim YOU wrote Mediawiki?

>   Go get a new book of insults. The one you use is clearly outdated,
> just as your grasp of reality, good coding practices for the 21st
> century and project managing.
>

Since when is the truth an insult?  When you work on toy sites, you can 
get by with toy coding.


-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#7082

FromAnders Wegge Keller <wegge@wegge.dk>
Date2012-09-16 00:39 +0200
Message-ID<87392idi7u.fsf@huddi.jernurt.dk>
In reply to#7080
Jerry Stuckle <jstucklex@attglobal.net> writes:

> Since when is the truth an insult? 

 That's why you are unable to insult me. 

-- 
/Wegge

Leder efter redundant peering af dk.*,linux.debian.*

[toc] | [prev] | [next] | [standalone]


#7083

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-09-15 18:45 -0400
Message-ID<k330f7$t2h$1@dont-email.me>
In reply to#7082
On 9/15/2012 6:39 PM, Anders Wegge Keller wrote:
> Jerry Stuckle <jstucklex@attglobal.net> writes:
>
>> Since when is the truth an insult?
>
>   That's why you are unable to insult me.
>

Glad you admit it's the truth.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#7084

FromAnders Wegge Keller <wegge@wegge.dk>
Date2012-09-16 00:59 +0200
Message-ID<87y5kac2og.fsf@huddi.jernurt.dk>
In reply to#7083
Jerry Stuckle <jstucklex@attglobal.net> writes:

> On 9/15/2012 6:39 PM, Anders Wegge Keller wrote:
> > Jerry Stuckle <jstucklex@attglobal.net> writes:
> >
> >> Since when is the truth an insult?
> >
> >   That's why you are unable to insult me.
> >
> 
> Glad you admit it's the truth.

 No, that's just to get rid of you. Your truth is that of a little
man, stuck on coding 100 hits/day webshops, hosted on GoDaddy. Your
truth is a constant lack of self-esteem, constant craving for
recognition, and constant lack of basic concepts, such as amortized
complexity, big-O notation, and for the lack of a better word, grasp
of language.

 You are unable to inslult me, because you are lying to yourself, when
you claim your half-witted cargo-cult programming as truth. Not
because I consider anything you say to be truth.

 You are a case out of psychology 101, and I pity you for having such
a shitty life. Normally I ignore yoy, but whenever you happen to
respond to me, your post is lifted above the kill-file. I'm sorry if I
gave you the impression that I normally read your mistaken ramblings.
 
-- 
/Wegge

Leder efter redundant peering af dk.*,linux.debian.*

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.php


csiph-web