Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 directory scanning function
Index -> Programming, PHP -> PHP Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
PaddyLong




PostPosted: Thu Aug 21, 2003 12:47 pm   Post subject: directory scanning function

this function would be especially useful for things like photo galleries or other things that require obtaining all the files in a directory (it uses regular expressions too, so you can get all the files of a specific type or named a certain way, etc etc)

note that this uses eregi so its searches are case insensitive... easily changed by changing it to ereg

code:

//this function is used to scan directories for certain filenames
/*
dir - the directory to scan
filenamepattern - the pattern expression to look for in the file names
empty - what to return if the directory is empty
*/

function scandir ($sdir, $filenamepattern, $empty){
        $filearray=array();
        $scanning = opendir($sdir);

        while (false != ($filename = readdir($scanning))){
                if (eregi($filenamepattern, $filename)){
                        $filearray[] = $filename;
                }
        }

        closedir($scanning);
        if (count($filearray)=="0"){
                $filearray[0]=$empty;
        }

        return $filearray;
}
Sponsor
Sponsor
Sponsor
sponsor
Homer_simpson




PostPosted: Thu Aug 21, 2003 2:52 pm   Post subject: (No subject)

heh... cool
+50 bits
Amailer




PostPosted: Thu Aug 21, 2003 8:31 pm   Post subject: (No subject)

Nice,
Ill use that for the pix display i .....was creating..some time ago..wonder where it is..


Anyways,
You guys know how some sites have 'How many sec it took to generate a page'?

code:

  /* Generated how long it page took to load
     it will display the result in seconds  */

  function utime () {
      $time = explode( " ", microtime());
          $usec = (double)$time[0];
          $sec = (double)$time[1];
          return $sec + $usec;
  }


          /* Some variables for the rending time of the page...
             How long the page took to load                 */
                $generate_start = utime();
                $generate_end = utime();
                $generate_run = $generate_end - $generate_start;
                $page_generate = "Page generated in approximately " .  substr($generate_run, 0, 5) . " seconds.";


Very Happy,

1 thing...how do i get the percentage of the PHP and MYSQL Queary it loaded? or w/e?

I.E: (4.06% PHP - 95.94% MySQL)
PaddyLong




PostPosted: Thu Aug 21, 2003 9:51 pm   Post subject: (No subject)

so you mean like is there any way to find out how much time it spent on sql queries and how much time it spent on parsing actual php? ...

well... I guess you could get the time of loading the page just before you do the query, and then again after you do the query, get the difference (after time - before time) of those and add that value to some total mySQL time variable .... and then for the php time it would be total time of document - mySQL time ...

and then the percents would be easy from there...

I know it might not be the cleanest way to do it... but it's the best way that I can think of (I couldn't find any predefined function that gets the time a query took ... closest was probably mysql_info() which looks like it just gives info about what tables, rows etc were affected or something)
Amailer




PostPosted: Fri Aug 22, 2003 12:19 am   Post subject: (No subject)

What about the PHP?
Like...the percentage of the PHP loaded on the page...
PaddyLong




PostPosted: Mon Aug 25, 2003 11:01 am   Post subject: (No subject)

well... assuming there's only mysql and php that you are dealing with do something like totalTime - mysqlTime = phpTime
Display posts from previous:   
   Index -> Programming, PHP -> PHP Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: