我有两个进程在彼此独立的不同脚本中运行。
- PHP #1 脚本读取文件的文件名并将其写入数据库
- PHP #2 脚本上传文件
我想创建第三个脚本(也是独立的),它仅在脚本#2 完全完成文件上传后执行。
我正在考虑使用PHP的flock函数来确定文件是否被锁定。我想脚本#3 需要包含某种设置在计时器上的羊群检查功能,以检查文件是否已解锁,如果是则继续。
注意:脚本 #3 会知道执行检查的文件名
有任何想法吗?如果文件可以链接起来会容易得多,但它们是独立执行的。
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.
脚本 2 在面向网页的页面中吗?如果是这样,我会向服务器发起 AJAX 调用以运行脚本 3。在脚本完成之前,页面无法呈现,一旦呈现,它就可以在页面加载时发起调用......