Thread: php: glob() vs opendir() and friends

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    169

    php: glob() vs opendir() and friends

    in the past ive done file structure handling in php with opendear readdir etc.

    someone told me i should start using glob becasue its better,

    on the php site for the glob function
    http://us2.php.net/glob
    someone posted this
    funny enough, but our testing opendir VS glob

    show advantage of opendir by speed

    0.00115704536438
    and
    0.0068039894104

    or if to pass 200 times
    0.210277080536
    vs
    1.2976038456
    so apparently opendir is faster (by alot)? or did this guy just do a bad test? or are there other reasons to use glob

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > someone told me i should start using glob becasue its better
    Better as in easier to use and you get pattern matching thrown in for "free"?

    Except they aren't free, so if you're always matching say "*" (for everything), then perhaps it's not so good, unless "*" is a special case inside glob.

    I notice the function has a bunch of flags you can specify, perhaps being a little more careful with your choices would help.

    It's one function wrapping up a lot of functions.

    > so apparently opendir is faster (by alot)?
    Seeing as you would only normally want to read it once, why would this matter in the grand scheme of things?

    Sure, if you have 000's of files, AND you want all of them, then opendir etc may be a better way.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed