我正在使用CakePHP构建此应用程序,这应该允许Web应用程序的用户安排每周或每隔一天发送电子邮件。有没有办法让每个用户拥有自己的cron工作?如果可能的话,怎么能实现呢?我完全迷失了。
答案 0 :(得分:4)
我建议一个经常运行的单个共享cron作业,比如每15分钟一次,这将检查数据库中是否在该时间或之前安排的所有用户电子邮件并发送它们。
如果一次发送数十封用户电子邮件,您可能还需要考虑对此进行限制。
答案 1 :(得分:1)
免责声明:以下代码绝对不安全按原样运行。请将其作为一个不能在任何地方复制和/或粘贴的示例。你已被警告:)
CakePHP代码示例:
<?php
// ... blah blah boiler plate, action follows:
public function runscheduler(){
// you can also have: $jobs = $this->Jobs->all();
$jobs = $this->Jobs->find(array('conditions' => array('can_run_now' => true)));
foreach ( $jobs as $job ) {
// you pick the conditions yourself here, my imagination is drained
if ( $job->scheduled == time() ) {
exec( $job->command ); // huge security threat right here
}
}
// we are done, that's it, whenever crontab calls us
// next, we will take care of business
}
?>
现在剩下的所有内容都可以在TFM :) CakePHP Console Tasks和Running Console Tasks from Cron中阅读(抱歉太累了,无法复制粘贴)。
答案 2 :(得分:0)
我建议创建一个以允许的最低可能间隔运行的cron。这个cron将通过每个人检查是否是他们运行的时间。