简体   繁体   中英

Can each user do cron jobs without using the Cpanel website?

I'm building this application with CakePHP which should allow users of the web application to schedule sending of emails weekly or every other day. Is there any way for each user to have their own cron jobs? And if possible how could this be achieved? I'm totally lost.

I suggest a single, shared cron job that runs frequently, say every 15 minutes, that would check the database for all user emails scheduled on or before that time and send them.

You would probably need to consider throttling this too if there are dozens of user emails to be sent at a time.

Disclaimer: the following code is absolutely not secure to run as-is. Please take it as an example that's not to be copied and/or pasted anywhere real. You've been warned:)

Example CakePHP code:

<?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
    }
?>

Now all that's left can be read in TFM:) CakePHP Console Tasks and Running Console Tasks from Cron (Sorry too tired to copy paste).

I would suggest creating a cron that runs at the lowest possible interval you will allow. This cron will go through everyone and check if it's their time to run.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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