简体   繁体   English

如何在PHP中轻松轻松地安排cron作业?

[英]How can I easily and simply schedule a cron job in PHP?

How can I easily and simply schedule a cron job in PHP? 如何在PHP中轻松轻松地安排cron作业? Rails has BackgroundRB... Rails具有BackgroundRB ...

Most website control panels (assuming you've got cPanel or something similar running) include a crontab application. 大多数网站控制面板(假设您已经运行cPanel或类似的东西)都包含crontab应用程序。 If you're on shared hosting ask your host about this. 如果您使用共享主机,请向您的主机询问。

If you're on a dedicated server and have installed cron then have a look at the crontab syntax . 如果您在专用服务器上并已安装cron,请查看crontab语法 These commands go in crontab , usually in /etc on *nix. 这些命令在crontab ,通常在* nix上的/etc

Here's a semi-PHP solution to add to a crontab: 这是添加到crontab的半PHP解决方案:

$cmd  = 'crontab -l > /tmp/crontab.bak'; // preserve current crontab
$cmd .= ' && echo "*/5 * * * * /foo/bar" >> /tmp/crontab.bak'; // append new command
$cmd .= ' && crontab /tmp/crontab.bak'; // update crontab
$cmd .= ' rm /tmp/crontab.bak'; // delete temp file

exec($cmd); // execute

PHP-Resque ,这是GitHub伙计们编写的队列和后台进程框架的PHP端口。

You're conflating a language with a framework. 您正在将语言与框架混为一谈。 PHP doesn't have a cron scheduling any more than Ruby does. 与Ruby相比,PHP没有cron调度。 If you're using a PHP framework or cms however, there is likely some utility for cron tasks. 但是,如果您使用的是PHP框架或cms,则可能有一些用于cron任务的实用程序。

Here is a useful link if you have control over the machine. 如果您可以控制机器,则这是一个有用的链接。 http://troy.jdmz.net/cron/ If you have shared hosting, there's probably some tool they'd give you for cron jobs; http://troy.jdmz.net/cron/如果您共享了主机托管,则可能有一些工具可以为您提供cron作业; ask them or look in the knowledge base. 询问他们或查看知识库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM