[nycphp-talk] Where to store tmp files? Where to store generated files?
justin
justin at justinhileman.info
Sat May 22 21:20:58 EDT 2010
On Sat, May 22, 2010 at 8:45 PM, Matt Juszczak <matt at atopia.net> wrote:
> Hi all,
>
> I have a quick question. I know in an application, if you need to create
> tmp files, it's probably best to use PHP's temporary file functions to
> create unique filenames in the location defined by php.ini/the environment.
> Is that correct?
>
Yup.
When doing this, remember that the POSIX standard requires than tmp
files are removed at the end of the current program execution. In the
case of PHP, this means that your file may (and should) disappear
after the current page request is finished.
> But in the case of needing to create files and store them for longer periods
> of time, where do you usually store them? I don't want to create a
> directory inside the code base, even if it is ignored by SVN. I also don't
> want to create the directory inside a system location, like /var, as I'd
> like the application to be kept separate from the system entirely. Storing
> the files inside MySQL is also an option, as that would be fairly portable
> and not require the use of an NFS mount in the future should the application
> grow large.
>
> What do you guys think?
Storing files in a DB is most likely a Bad Idea. I generally store
files in the filesystem and paths in the DB. When the application
grows large, it's a pretty easy transition to store files in the cloud
(S3) and URLs in the DB.
But where do these files belong? I usually go with a directory
structure something like this:
myprogram
myprogram/app
myprogram/tmp
myprogram/var
myprogram/web
Then point apache at `/web`, put the app code in `/app`, put tmp files
in `/tmp`, and put persistent app-writable files in `/var`. Then tell
your SCM to ignore the contents of `/tmp` and `/var`.
-- justin
More information about the talk
mailing list