[英]How to run a php function after certain time without using cron
I have a block of code and want to run it after certain time intervals, say after every 3 seconds. 我有一段代码,想在一定的时间间隔后运行,例如每3秒运行一次。 If I get required result it should die otherwise another request will be sent after 3 seconds. 如果我得到要求的结果,它将死掉,否则3秒后将发送另一个请求。 Any idea to do it with php. 任何想法用PHP做到这一点。
Thanks in advance for any help 预先感谢您的任何帮助
You can sleep in a loop: 您可以循环睡觉:
while (true) {
$result = doSomething;
if (resultIsGood) {
break;
}
sleep(3);
}
If you don't want to keep the browser waiting, you can look up ignore_user_abort()
solutions on Google. 如果不想让浏览器处于等待状态,可以在Google上查找ignore_user_abort()
解决方案。
If what you want to execute MySQL queries (and nothing else), maybe using the MySQL event scheduler could fit your need: 如果您想执行MySQL查询(而不执行其他任何操作),则也许可以使用MySQL事件调度程序来满足您的需求:
http://dev.mysql.md/doc/refman/5.5/en/events-overview.html http://dev.mysql.md/doc/refman/5.5/en/events-overview.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.