Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Email sending with cron jobs
  • I am learning about Fuel PHP in these days.Now, I am trying to write a function. When the customers log out from my system, I would like to send "Thanks You" email after 3 days. So if one customer log out, new tasks will become. Although I had learned about using cron jobs,  I don't know how to add cron tasks in putty by coding from Fuel PHP.
  • HarroHarro
    Accepted Answer
    You write a FuelPHP task (see the docs), and in your cron job, you put something like

    30 2 * * * root /usr/bin/php /your/fuel/path/here/oil refine yourtask

    which will run the task called "yourtask" every night at 2:30 server time.

    A task has full framework access, so you can do anything in a task you can do in a controller. Only sending out HTML is less useful. ;-) But you can use Cli::write() to output to the console.
  • Oh...Great!!..Sir Harro Verton
    Thanks you very much for your answer.
    I'll try it.
  • I wrote the following new task in Tasks of FuelPHP .

    class Sentmail
    {
    public static function run()
    {
    //Email Sending for Thank you
    \Package::load('email');
    $email = Email::forge();
    // Set the from address
    $email->from('contact@testing.net', 'System Manager');
    // Set the to address
    $email->to('sample@gmail.com');
    // Set a subject
    $email->subject('Thanks You');
    // And set the body.
    $email->body('Thanks You ');

    $email->send();
    }
    }

    and From CronTab , 

    1 * * * *  /usr/bin/php /vagrant/bin/hotel_cs/oil r sentmail

    and then I accept a new mail in /var/spool/mail/vagrant
    image Can you help me, Sir Harro.
  • HarroHarro
    Accepted Answer
    It looks like the file isn't there?
  • yes.My fuel file is under vagrant  like that /vagrant/hotel_cs. 
    and then I connected this file with /var/www/html using symbolic link.

  • HarroHarro
    Accepted Answer
    Which users crontab is that? It doesn't look like the system cron file, so you might have an issue with permissions.
  • I am using in Putty , I wrote crontab -e and then following command:

    50 3 * * * /usr/bin/php /vagrant/bin/hotel_cs/oil r sentmail
    and later ,
    I got a new Email at /var/spool/mail/vagrant.
  • if you do "crontab -e", you create a cron entry for the user you are currently logged-in at.

    Does that user have (the correct) access to the fuel files?
  • Thanks Sir...now I got it. And I want to know "Can I write the above Sentmail class in the task??"
    I got error like that.
    image
    image
  • Sentmail Class is the following Sir.
    image
    image
  • No images?
  • Thanks you . Mr. Harro Verton.
    Recently, I can sent email by Crontab command in Putty by calling the mail send function in the task. Now I would like to know how to manage cronjob with fuelphp code. Although I am learning Here , I want to know what we can do in another ways?
  • Not sure I understand what you mean? What exactly do you want to manage?
  • I want to write CronJob command to Cron File in PHP code, Not in Putty.  
    May be like that.

    $hrs = date('G', strtotime($txtschedual));

    $mints = (int)date('i', strtotime($txtschedual));
    $uniqueid = uniqid();
    $cronFile = getcwd()."/schedule/thecommand".$this->sessionAdmin->user_id."".$this->sessionAdmin->username.$uniqueid.".sh";
    $fh = fopen($cronFile, 'w') ;
    chmod($cronFile,0777);
    $stringData = "wget -O -q -t 1 ".BASE_URL."file.php?from=".strtotime($_POST['schedual'])."";
    fwrite($fh, $stringData);
    fclose($fh);

    $crontab = new Ssh2_crontab_manager(SSH2_HOST, SSH2_PORT, SSH2_USERNAME, SSH2_PASSWORD); 
    $cronDatetime = $mints.' '.$hrs.' * * * '.$cronFile;
    $crontab->append_cronjob($cronDatetime);

    But I'm not understand about the code to connect cron file.How can I connect cronfile from fuelphp?

  • Have a look at https://www.codeyellow.nl/queue.html

    You would have a cron job that fires the queue processor (every minute, 5 minutes), it would pick up any jobs in the queue. You could extend it to run time based jobs as well.
  • Thanks for your reply again. I'll be try it . How about 

    PHPSecLib?


  • That is not related to cron jobs afaik?

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion