Thread safe file system access

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
greenhorn666
Forum Commoner
Posts: 87
Joined: Thu Aug 14, 2003 7:14 am
Location: Brussels, Belgium

Thread safe file system access

Post by greenhorn666 »

I am about to create an update system for a database that uses a CSV file to update/insert rows in postgresql database's tables.

I was thinking of a crontab entry that scans the FS for a newer upload than it's last execution time (about every minute). If a file is present it launches the update script. The problem I see coming is 'What if the upload isn't terminated yet?'
Well, in our case here it wouldn't be that bad, since only valid cvs lines will go for the update that itselfs happens in a transaction.

But is there a way to verify that no file descriptor is open the file before proceeding with the update? or any other solution, hint, idea is welcome...

Otherwise I'll go for a #!/bin/bash with lsof on the file...
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

In the upload script, the final action could be to log upload success somewhere.

Update script could check the log entries before proceeding.
User avatar
greenhorn666
Forum Commoner
Posts: 87
Joined: Thu Aug 14, 2003 7:14 am
Location: Brussels, Belgium

Post by greenhorn666 »

Well since the upload happens over FTP, I can make have php to create a lock file somewhere... I've done it with a small bash script using lsof to check if the file is still in use...
Thanks anyhow ;)
Post Reply