I have two processes running in different scripts indepdent of each other.
- PHP #1 script reads the filename of a file and writes it to a DB
- PHP #2 script uploads the file
I would like to create a third script (also independent) that only executes once script #2 has fully completed uploading the file.
I'm thinking of using PHP's flock function to determine if the file is locked. I imagine script #3 would need to contain some sort of flock check function that was set on a timer to check to see if the file was unlocked, and if so to proceed.
Not开发者_运维技巧e: script #3 would know the filename to perfom the check
Any ideas? It would be a lot easier if the files could be chained, but they execute indepently.
is script 2 in a web facing page? if so, I would fire back a AJAX call to the server to run script 3. The page can't render until the script is done, and once it renders it can fire back the call on page load...
I don't know if the file is locked all the time while it's being written to so I wouldn't rely on that.
I would check for changes in the file size at intervals (in conjunction with flock). And when the files stops growing consider that it finished uploading.
If you have control over the 2nd script just trigger the 3rd one when it finishes execution (``). Or if that is not possible use a file or something to feed the upload state from #2 and to read it from #3.
精彩评论