This article will explain How to Using cronjob in yii1 to making a file every minutes.
1) First, create a file in /protected/commands/CronjobCommand.php
2. Copy the following script :
<?php class CronjobCommand extends CConsoleCommand{ public function actionCreateFile(){ $new_file = date('Y-m-d H:i:s') . '.txt'; $dir = "/var/www/html/yii1/cron/" . $new_file; $f = fopen($dir, 'w'); fclose($f); } }
3) Then, create a folder “cron” inside /yii1/. This folder will be used to store the file.
4) Now, trying to run “CronjobCommand.php” from console.
Open your terminal, type :
cd /var/www/html/yii1/protected/
To run CronjobCommand.php via console, type :
php yiic Cronjob CreateFile
We will see a new file inside “cron” folder :
5) All right, now we will make cronjob. Type below in your terminal :
crontab -e
The following script will be execute CronjobCommand.php every minutes :
* * * * * php /var/www/html/yii1/protected/yiic Cronjob CreateFile
Then save (ctrl + x)