Symfony Cron Job

It is good to know that you can use symfony from command line and automate periodic tasks with cron (i.e. sending mails, sms reminders, checking log files, etc.)

Here is one symfony cron job example:

<?php

define('SF_ROOT_DIR',    realpath(dirname(__file__).'/..'));
define('SF_APP',         'front');
define('SF_ENVIRONMENT', 'prod');
define('SF_DEBUG',       false);

require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');

$context = sfContext::getInstance();

date_default_timezone_set('Europe/Sarajevo');

$now = date('Y-m-d H:i:s');
$five_min = time() + (5 * 60);
$nextCron = date('Y-m-d H:i:s', $five_min);

$c = new Criteria();
$c->add(ReminderPeer::SCHEDULED_AT, $now, Criteria::GREATER_THAN);
$c->add(ReminderPeer::SCHEDULED_AT, $nextCron, Criteria::LESS_THAN);

$reminders = ReminderPeer::doSelect($c);

if ($reminders)
{
	foreach ($reminders as $reminder)
	{
	$sms = new Sms();
		if ($sms->sendReminder($reminder))
		{
			$reminder->delete();
		}
	}
}

?>






Comments are closed.