Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #7077
| Newsgroups | comp.lang.php |
|---|---|
| Subject | Re: How expensive is glob'ing a dir and including all the files? |
| References | <38015b6a-5ef2-4f92-9aa2-6eea01c7097a@googlegroups.com> <87mx0rddit.fsf@huddi.jernurt.dk> <k31uvt$8b0$1@dont-email.me> |
| From | Anders Wegge Keller <wegge@wegge.dk> |
| Date | 2012-09-15 23:41 +0200 |
| Message-ID | <87haqzc6bl.fsf@huddi.jernurt.dk> (permalink) |
| Organization | SunSITE.dk - Supporting Open source |
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.*
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
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
csiph-web