PHP - 好cronjob / crontab / cron教程或书 [英] PHP - good cronjob/crontab/cron tutorial or book

查看:140
本文介绍了PHP - 好cronjob / crontab / cron教程或书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一个好的cronjob教程或书,以了解如何使用PHP创建一个。

I'm looking for a good cronjob tutorial or book to learn how to create one using PHP.

推荐答案

Cronjob是不是作为Php进程或脚本创建的东西。 Cron 是一个Linux程序,允许您定期调用脚本。

Cronjob is not something to create as Php process or script. Cron is a linux program that allows you to call a script at a regular interval.

您可以通过以管理员用户身份输入您的Linux机器来查看什么是crontab,然后输入:

You can see what is an crontab by entering in your linux machine as an admin user and type:

root@valugi:~# crontab -e

*/1 * * * * /usr/bin/php /var/www/somesite/public/cron.php

这意味着我每分钟执行cron.php。

This means that each minute I am executing the cron.php.

现在,您可能希望在不同时间执行不同的脚本,并希望将此逻辑传递到php级别而不是linux级别。如果是这种情况,你可能想要调用cron脚本在最低时间分母(例如分钟)和cron.php构建一些逻辑,将调用在不同的时间其他脚本。

Now, you may want to have different scripts executed at different times and want to pass this logic to php level instead of linux level. If this is the case you may want to call your cron script at the lowest time denominator (minute for example) and in the cron.php build some logic that will call at different times other scripts.

我使用例如Cronable接口:

I use for example a Cronable interface:

interface Cronable {
    public function cron();
}

想要由cron.php调用的每个类都必须实现这个接口和cron()函数,它将指定什么是特定的调用频率。 cron.php将获得所有这些类,并将当前时间与该时间进行比较,并决定是否执行调用。

And each class that wants to be called by the cron.php has to implement this interface and the cron() function, which will specify what is the specific frequency of the call. The cron.php will get all this classes and will compare current time with that time and will decide to execute the call or not.

这篇关于PHP - 好cronjob / crontab / cron教程或书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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