PHP Flock 和文件上传

发布于 2024-09-29 04:22:45 字数 301 浏览 2 评论 0原文

我有两个进程在彼此独立的不同脚本中运行。

  1. PHP #1 脚本读取文件的文件名并将其写入数据库
  2. PHP #2 脚本上传文件

我想创建第三个脚本(也是独立的),该脚本仅在脚本 #2 完全完成上传文件后执行。

我正在考虑使用PHP的flock函数来确定文件是否被锁定。我想脚本 #3 需要包含某种在计时器上设置的集群检查功能,以检查文件是否已解锁,如果是则继续。

注意:脚本 #3 会知道执行检查的文件名

有什么想法吗?如果文件可以链接起来会容易得多,但它们独立执行。

I have two processes running in different scripts indepdent of each other.

  1. PHP #1 script reads the filename of a file and writes it to a DB
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夕嗳→ 2024-10-06 04:22:45

脚本 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...

紫罗兰の梦幻 2024-10-06 04:22:45

我不知道文件在写入时是否始终处于锁定状态,因此不会依赖于此。

我会定期检查文件大小的变化(与集群一起)。当文件停止增长时,认为它已完成上传。

如果您可以控制第二个脚本,只需在第三个脚本完成执行时触发它(``)。或者,如果不可能,请使用文件或其他东西来提供#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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文