<i id='YRNLB'><tr id='YRNLB'><dt id='YRNLB'><q id='YRNLB'><span id='YRNLB'><b id='YRNLB'><form id='YRNLB'><ins id='YRNLB'></ins><ul id='YRNLB'></ul><sub id='YRNLB'></sub></form><legend id='YRNLB'></legend><bdo id='YRNLB'><pre id='YRNLB'><center id='YRNLB'></center></pre></bdo></b><th id='YRNLB'></th></span></q></dt></tr></i><div id='YRNLB'><tfoot id='YRNLB'></tfoot><dl id='YRNLB'><fieldset id='YRNLB'></fieldset></dl></div>
      1. <tfoot id='YRNLB'></tfoot>

        <legend id='YRNLB'><style id='YRNLB'><dir id='YRNLB'><q id='YRNLB'></q></dir></style></legend>
      2. <small id='YRNLB'></small><noframes id='YRNLB'>

        • <bdo id='YRNLB'></bdo><ul id='YRNLB'></ul>
      3. PHP:如何避免读取通过 FTP 推送给我的部分文件?

        时间:2023-10-30

          <small id='CJoJ0'></small><noframes id='CJoJ0'>

              • <bdo id='CJoJ0'></bdo><ul id='CJoJ0'></ul>

              • <i id='CJoJ0'><tr id='CJoJ0'><dt id='CJoJ0'><q id='CJoJ0'><span id='CJoJ0'><b id='CJoJ0'><form id='CJoJ0'><ins id='CJoJ0'></ins><ul id='CJoJ0'></ul><sub id='CJoJ0'></sub></form><legend id='CJoJ0'></legend><bdo id='CJoJ0'><pre id='CJoJ0'><center id='CJoJ0'></center></pre></bdo></b><th id='CJoJ0'></th></span></q></dt></tr></i><div id='CJoJ0'><tfoot id='CJoJ0'></tfoot><dl id='CJoJ0'><fieldset id='CJoJ0'></fieldset></dl></div>
                <tfoot id='CJoJ0'></tfoot>

                    <tbody id='CJoJ0'></tbody>
                • <legend id='CJoJ0'><style id='CJoJ0'><dir id='CJoJ0'><q id='CJoJ0'></q></dir></style></legend>
                • 本文介绍了PHP:如何避免读取通过 FTP 推送给我的部分文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  文件正在通过 FTP 推送到我的服务器.我在 Drupal 模块中使用 PHP 代码处理它们.操作系统是Ubuntu,FTP服务器是vsftp.

                  Files are being pushed to my server via FTP. I process them with PHP code in a Drupal module. O/S is Ubuntu and the FTP server is vsftp.

                  我会定期检查新文件,使用 SimpleXML 处理它们并将它们移动到完成"文件夹.如何避免处理部分上传的文件?

                  At regular intervals I will check for new files, process them with SimpleXML and move them to a "Done" folder. How do I avoid processing a partially uploaded file?

                  vsftp 的 lock_upload_files 默认为 yes.我想先尝试移动文件,期望移动在当前上传的文件上失败.这似乎没有发生,至少在命令行上是这样.如果我开始上传一个大文件并移动,它只会在新位置不断增长.我猜目录项没有被锁定.

                  vsftp has lock_upload_files defaulted to yes. I thought of attempting to move the files first, expecting the move to fail on a currently uploading file. That doesn't seem to happen, at least on the command line. If I start uploading a large file and move, it just keeps growing in the new location. I guess the directory entry is not locked.

                  我应该在尝试加载到 SimpleXML 之前尝试使用模式a"或r+"来查看它是否成功,还是有更好的方法来做到这一点?我想我可以检测到 SimpleXML 加载失败,但是……这看起来很乱.

                  Should I try fopen with mode 'a' or 'r+' just to see if it succeeds before attempting to load into SimpleXML or is there a better way to do this? I guess I could just detect SimpleXML load failing but... that seems messy.

                  我无法控制发件人.他们不会进行上传和重命名.

                  I don't have control of the sender. They won't do an upload and rename.

                  谢谢

                  推荐答案

                  如果锁定不起作用,我不知道有什么解决方案像您想要的那样干净/简单.您可以通过不处理上次修改时间的文件来做出有根据的猜测(您可以使用 filemtime()) 在过去 x 分钟内.

                  If locking doesn't work, I don't know of a solution as clean/simple as you'd like. You could make an educated guess by not processing files whose last modified time (which you can get with filemtime()) is within the past x minutes.

                  如果您想要比这更高的置信度,您可以检查并存储每个文件的大小(使用 filesize()) 在一个简单的数据库中,并且每 x 分钟检查新大小与旧大小.如果大小在 x 分钟内没有改变,您可以假设没有更多内容被发送.

                  If you want a higher degree of confidence than that, you could check and store each file's size (using filesize()) in a simple database, and every x minutes check new size against its old size. If the size hasn't changed in x minutes, you can assume nothing more is being sent.

                  这篇关于PHP:如何避免读取通过 FTP 推送给我的部分文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 PHP 或 Python 从 FTP 服务器读取或下载 5kb 文件,而不是下载或读取整个文件 下一篇:PHP ftp_put 失败,并出现“警告:ftp_put (): PORT 命令成功"

                  相关文章

                  <legend id='Hniqj'><style id='Hniqj'><dir id='Hniqj'><q id='Hniqj'></q></dir></style></legend>
                • <tfoot id='Hniqj'></tfoot>

                  1. <i id='Hniqj'><tr id='Hniqj'><dt id='Hniqj'><q id='Hniqj'><span id='Hniqj'><b id='Hniqj'><form id='Hniqj'><ins id='Hniqj'></ins><ul id='Hniqj'></ul><sub id='Hniqj'></sub></form><legend id='Hniqj'></legend><bdo id='Hniqj'><pre id='Hniqj'><center id='Hniqj'></center></pre></bdo></b><th id='Hniqj'></th></span></q></dt></tr></i><div id='Hniqj'><tfoot id='Hniqj'></tfoot><dl id='Hniqj'><fieldset id='Hniqj'></fieldset></dl></div>

                  2. <small id='Hniqj'></small><noframes id='Hniqj'>

                      • <bdo id='Hniqj'></bdo><ul id='Hniqj'></ul>