PHP Flock 和文件上传
我有两个进程在彼此独立的不同脚本中运行。
- PHP #1 脚本读取文件的文件名并将其写入数据库
- PHP #2 脚本上传文件
我想创建第三个脚本(也是独立的),该脚本仅在脚本 #2 完全完成上传文件后执行。
我正在考虑使用PHP的flock函数来确定文件是否被锁定。我想脚本 #3 需要包含某种在计时器上设置的集群检查功能,以检查文件是否已解锁,如果是则继续。
注意:脚本 #3 会知道执行检查的文件名
有什么想法吗?如果文件可以链接起来会容易得多,但它们独立执行。
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.
Note: 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
脚本 2 是否位于面向网页的页面中?如果是这样,我会向服务器发起 AJAX 调用以运行脚本 3。在脚本完成之前,页面无法呈现,一旦呈现,它就可以在页面加载时激发调用...
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...
我不知道文件在写入时是否始终处于锁定状态,因此我不会依赖于此。
我会定期检查文件大小的变化(与集群一起)。当文件停止增长时,认为它已完成上传。
如果您可以控制第二个脚本,只需在第三个脚本完成执行时触发它(``)。或者,如果不可能,请使用文件或其他东西来提供#2 中的上传状态并从#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.