Answer the question
In order to leave comments, you need to log in
How to set up cron in yii application?
Run a cron job on a virtual host
<?php
$_SERVER["argv"][0]='Cron';
$_SERVER["argv"][1]='Cron';
if (!ini_get('register_argc_argv')) {
if(ini_set('register_argc_argv', '1')){
echo "Установилось \n";
} else {
echo "Не удалось установить \n";
}
}
// change the following paths if necessary
$yiic=dirname(__FILE__).'/../../yii-1.1.16.bca042/framework/yiic.php';
$config=dirname(__FILE__).'/config/console.php';
$_SERVER['SCRIPT_FILENAME'] ='__DIR__';
require_once($yiic);
Yii::createConsoleApplication($config)->run();
?>
class CronCommand extends CConsoleCommand
{
public function run($args)
{
$criteria=new CDbCriteria;
$criteria->compare('id_status',1);
$criteria->addCondition('date_started <=NOW()');
$started=MusicTest::model()->findall($criteria);
foreach($started as $model){
$model->id_status=2;
}
$criteria=new CDbCriteria;
$criteria->compare('id_status',2);
$criteria->addBetweenCondition('date_finished','0000-00-00 00:00:01',date(" Y-m-d H:i:s") );
$finish=MusicTest::model()->findall($criteria);
foreach($finish as $model){
$model->id_status=3;
$model->save();
}
}
}
Answer the question
In order to leave comments, you need to log in
Why do you need all this pandemonium?
$_SERVER["argv"][0]='Cron';
$_SERVER["argv"][1]='Cron';
50 3 * * * cd /usr/local/www/site.com/ && php ./yiic cron
1. To check if there is something in a substring, it's better to
use php.net/manual/ru/function.mb-strpos.php
etc. In general, if the task is "live", then it's better not to do it ever.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question