使用 PHP 例行显示数据
我想经常使用 PHP 做一些事情。
例如,假设我想每 5 秒显示一些内容:
while(true) {
sleep(5);
echo "Test!";
}
但这是行不通的,因为它是一个无限循环。
那么,这样做的正确方法是什么?
这只是我想要做的事情的简化,我想在每次更改时从文件中提取数据并将其插入到 SQLite 数据库中,但是了解如何正确执行前面的示例会对我有很大帮助。我不知道是否有更好的方法来代替使用 PHP,所以请告诉我我是否错了。
I want to routinely do something using PHP.
For example, imagine that each 5 seconds I want to display something:
while(true) {
sleep(5);
echo "Test!";
}
But this won't work because it's an infinite loop.
So, what would be the correct way to do this?
This is only a simplification of what I want to do, I would like to extract data from a file every time it changes and insert it into a SQLite database, but understanding how to do the previous example correctly would help me a lot. I don't know if there is a better way to do this instead of using PHP, so please tell me if I'm wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 cron 作业定期调用脚本怎么样?我知道这是最常见的方法。不过,最小粒度是每分钟......
What about using a cron job to call your script periodically? I understand it's the most common way to do it. The minimum granularity would be each minute, though...
编辑:忽略我之前的回答。我相信 cron 将是最简单的方法。
如果您使用的是 Windows 服务器,这会有所帮助:http://drupal.org/node/31506
Edit: Ignore my previous answer. I believe cron would be the easiest way to go about it.
If you're working on a windows server this will help: http://drupal.org/node/31506