如何使PHP函数每5秒循环一次 [英] how to make a php function loop every 5 seconds

查看:160
本文介绍了如何使PHP函数每5秒循环一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个php函数,它使用php本身每秒更新一次,而没有其他语言,只是纯PHP代码.

I am tyring to make a php function that updates every second using php itself no other languages, just pure PHP codes.

function exp(){
//do something
}

我希望它每秒返回一个值.就像每秒更新一次.

I want it to return a value each second. Like update every second.

推荐答案

最好不要在PHP中进行此操作,而是通过计算从数据库获得的时间与当前时间之间的差值来尝试在客户端进行操作. 您可以像这样在JS中创建该代码:

It's not preferable to make this in PHP, try to make on client side by calculating difference between time you got from database and current time. you can make this in JS like this:

setInterval(function(){
      // method to be executed;
    },5000);  // run every 5 seconds

这篇关于如何使PHP函数每5秒循环一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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