Ryan A wrote:
Hey, Heres my setup, I have a directory full of files and I get a request with an array of filenames For this example: a.txt b.txt c.txt if the above files dont already exist I need to create them (I am using touch() instead of fopen()) My question is which would you recommend, doing a readdir() and getting all the existing filenames in an array then doing a loop to see which exists and create the others OR just taking the new filenames, doing a while/for loop with a files_exists() on each and then creating the files.... I am favouring the second approach as in the first approach there are a lot of files the array could be pretty big which would cause other problems, but I would rather be corrected now if my thinking is flawed.
It depends on: --the number of files in the directory --the the number of files being added/updated --the liklihood that a file in the request will be new Here are a couple of general principles to follow: --KISS. Start with the simplest solution. Complicate it only to optimize it and then only if optimization is really necessary. --A system call is relatively expensive and time-consuming. If you are literally only touching the files that don't exist (to create an empty file), consider building a shell script that does the whole batch in one system call. --John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php