From: Ashley M. Kirchner

> Is there a clean or reliable way of checking to see if a
> file is still being written to before doing anything with it?
> Here's the scenario: we have a Samba share that we can copy
> files to (from within Windows or Macs).  The server picks up
> the file and does some processing of said file.  At the moment
> this is all a manual process: we copy a file into the Samba
> share, wait for that to finish then go to a web page (on the
> server) and tell it to process the file that was just copied
> into the Samba share.  I'm trying to see if there is a way to
> automate this where a file, or multiple files, get copied into
> the share and the server picks them up and process automatically
> without needing any interaction.
> Can PHP detect this, or should I look into some delayed
> process of checking the file's modified time stamp versus current
> time and not touch the file till a certain threshold has been
> reached (say 30 seconds difference?).

Write the file with a temporary name and extension. Once the file is
closed, change the name to the pattern your server is looking for. Once
you finish processing it, either change the name again, or move it to a
different directory. Don't reuse the same file name, but add a numeric
value which increases every time you create it. Keep a log of which
files have been processed and any errors each one produced.

Bob McConnell

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to