简体   繁体   English

如何在一定时间后不使用cron来运行php函数

[英]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.

相关问题 如何在不使用exec或系统功能的情况下运行cron作业? - How to run a cron job without using exec or system function in PHP? 固定时间后运行cron作业以执行php函数 - Run cron job to execute a php function after some fixed time 在不使用Cron的情况下,根据给定的时间自动执行php函数 - Execute a php function automatically according to a given time without using Cron 设置cron与在特定时间后运行的参数,并使用php删除该cron作业一旦执行完成 - set cron with parameter that run after specific time and than delete that cron job once execution complete using php 在后台运行PHP脚本(不使用Cron) - Run PHP Script in Background(Without Using Cron) 从用户定义的开始时间到结束时间运行一行PHP代码,而不使用CRON作业 - Run a line of PHP code from user defined start time to end time without using CRON jobs 在经过一定的延迟后如何不使用sleep()从另一个PHP api文件运行一个php api文件? - How to run a php api file from another php api file after a certain delay, and without using sleep()? 我如何只允许cron在特定时间内在PHP文件上运行 - How can I only allow cron to be run on a PHP file during a certain time 如何在不使用cron的情况下每天在Wordpress和PHP中调用函数? - How to call a function daily in Wordpress & PHP without using cron? 如何使用cron运行php脚本 - How to run a php script using cron
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM