等待文件存在! [英] waiting for file to exist!

查看:70
本文介绍了等待文件存在!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮我设置一个循环来等待文件存在吗?


i有一个自动程序从下载文件我的ftp,处理文件

并将结果作为文件返回!


我现在正在做的就是睡觉(15);到我站点中执行的文件等待文件!! ,问题是文件的处理可能需要1秒一段时间,有些时间3秒,我把15秒确保文件将在那里!!


什么我可以让我的代码等待文件存在,然后继续!!


有一种方法可以将睡眠置于循环中吗?喜欢:

展开 | 选择 | Wrap | < span class =codeLinkonclick =LineNumbers(this);>行号

解决方案

你要求的是创建一个"无限"环。替换某事在你的while循环中有一些永远是真的东西。显然像1 == 1或只是简单的值真。


这会耗尽你的记忆,但不会有效率。我建议你把它放在一个预定的job / crontab任务中,并让它经常执行。这意味着消除循环,只需创建一个PHP文件,检查文件是否存在,如果不是只是正常退出;如果是,则处理文件(并在完成后重命名/删除它)


有问题吗?




Dan


这就是我需要的! ,我认为这是唯一的方法,我无法告诉cron工作的所有细节,因为cron工作不是在读我的文件!! ,如果你可以帮我解决这个问题,那就太棒了! ,我需要为我的代码睡一觉!!

这是我认为最适合我需要的方式!!


thanx !!


一个cron作业将无法读取你的文件,它只会调用你的php程序,你的php程序处理你的文件。


只需要做这样的cron工作,将15改为你想要的任何分钟:

展开 | 选择 | Wrap | 行号

can someone please help me set up a loop to wait for a file to be
exist?

i got a automation program that download a file from my ftp ,proccessing the file
and returning back the result as a file!

what im doing right now is im puting a sleep(15); to the executed file in my site to wait for the file!! ,the problem is that the proccesing of the file can take 1 second some time ,and some time 3 seconds, i put 15 seconds to be sure the file will be there!!

what can i do make my code wait for the file to be exist ,then continue!!

there is a way to put the sleep in a loop? like :

Expand|Select|Wrap|Line Numbers

解决方案

what you''re asking for is to create an "infinite" loop. replace "something" in your while loop with something that will always be true..obviously something like 1==1 or just simply the value "true".

This will eat up your memory though and won''t be efficient. I suggest you put this in a scheduled job/crontab task and make it execute every so often. That means eliminate the loop, just create a PHP file that checks to see if a file is there, if not just exits gracefully; if yes, processes the file (and rename/removes it when done)

Any questions?





Dan


this is what i need ! ,i think this is the only way to do that ,i cannot tell the cron job all the details ,becuse the cron job is not reading my files!! ,if you can help me with my quastion that will be great! ,i need to put a sleep to my code!!
this is the way i think is best for my needs!!

thanx!!


well a cron job wouldn''t read your file, it would just call your php program, your php program deals with your file.

just do a cron job like this, changing the 15 to any minutes that you want:

Expand|Select|Wrap|Line Numbers


这篇关于等待文件存在!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆