generate a unique hash as the name based on the contents of the zip, then if 2 people
happen to want exactly the same selection you won't have to build/zip it twice ...
just check if the zip happens to exist before trying to build it.
have the script do garbage collection on old zip files ... in a script specific 'tmp'
dir that stores the created zipfiles ... the GC can kick in on 1% of every requests (and
maybe limits itself the ammount of time spent GCing)
to elliminate race conditions completely you'll have to use a lock file,
which the script needs to exclusively lock before attempting to create the zip ...
a failure to get an exclusive lock means having to recheck the zip's existence
(chances are some other script just created it). in addition a shared lock should be
obtained before trying to read a zip, to avoid reading half written files.
Kyle Browning schreef:
Write a script that cron runs that checks dates of files and removes 1 month
old ones?
On Wed, Jul 9, 2008 at 4:45 PM, tedd <tedd@xxxxxxxxxxxx> wrote:
Hi gang:
Here's the logic problem.
First the site:
http://php1.net/b/zip-files/
Now, the site works well enough. The user selects what they want, clicks
Submit, the order is assembled in zip file and presented to the user for
downloading.
However, as it stands now, before the script assembles the test.zip, it
deletes (unlinks) the previous test.zip and therein lies the problem.
If two, or more, users hit the site at the same time then a RACE condition
may have one user getting something they didn't ask for or not getting
anything at all.
The complicated way I figure I could solve this would be to:
1. Generate a random string name for the file -- instead of test.zip, it
could be ax12nhg34.zip.
2. Then when the user selects the download that would trigger a javascript
routine that would send the name of the file to be deleted to a slave php
script that would unlinks the file.
I know this will work, but if the user never downloads the file, then the
files accumulate on the server.
Does anyone have a better idea?
Thanks,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php