php: glob() vs opendir() and friends

This is a discussion on php: glob() vs opendir() and friends within the Tech Board forums, part of the Community Boards category; in the past ive done file structure handling in php with opendear readdir etc. someone told me i should start ...

  1. #1
    They Call me Mister Sako
    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
    AIM: MisterSako | MSN: sakotheinsane@hotmail.com | E-mail: klinerr1@nc.rr.com
    The goal of computer science is to be lazy

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,453
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21