PHP: running scheduled jobs (cron jobs)(PHP:运行预定作业(cron 作业))
问题描述
我的 webhotel 上有一个站点,我想在其上运行一些计划任务.您会推荐哪些方法来实现这一目标?
I have a site on my webhotel I would like to run some scheduled tasks on. What methods of achieving this would you recommend?
到目前为止,我想到的是在每个页面的顶部包含一个脚本,然后让该脚本检查是否该运行该作业.
What I’ve thought out so far is having a script included in the top of every page and then let this script check whether it’s time to run this job or not.
这只是我所想的一个简单例子:
This is just a quick example of what I was thinking about:
if ($alreadyDone == 0 && time() > $timeToRunMaintainance) {
runTask();
$timeToRunMaintainance = time() + $interval;
}
还有什么我应该考虑的吗?还有比这更好的方法吗?
Anything else I should take into consideration or is there a better method than this?
推荐答案
这就是 cronjobs 的用途.man crontab 假设您正在运行 Linux 服务器.如果您没有 shell 访问权限或无法设置 cronjobs,可以使用免费服务在外部服务器上设置 cronjobs 并 ping 您的 URL 之一.
That's what cronjobs are made for. man crontab assuming you are running a linux server. If you don't have shell access or no way to setup cronjobs, there are free services that setup cronjobs on external servers and ping one of your URLs.
这篇关于PHP:运行预定作业(cron 作业)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP:运行预定作业(cron 作业)
基础教程推荐
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何替换eregi() 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
