Re: touch()ing it....advise needed.

From: Date: Sat, 13 May 2006 17:49:09 +0000
Subject: Re: touch()ing it....advise needed.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-236115@lists.php.net to get a copy of this message
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

« previous php.general (#236115) next »