Cronjob does not recognize the Codeiginiter controller

Asked

Viewed 88 times

1

I’m trying to make a cronjob run in the IC, but I’m not getting, this error appears:

Fatal error: Class 'Ci_controller' not found in /Meucaminho/application/controllers/cron.php online 4

PHP

<?php 
class Cron extends CI_Controller{ 
//put your code here 
public function index(){ 
    $arq = fopen("teste_cron.txt", "a+"); 
    fwrite($arq, "=======================TESTE CRONTAB======================================\n"); 
    fwrite($arq, "O CronTab executou este código na Data/Hora: ".date("d/m/Y H:i:s")."\n"); 
    fwrite($arq, "==========================================================================\n"); 
    fclose($arq); 
}} 

WAY

php -q /home/user/public_html/caminho_completo/application/controllers/cron.php 

Can anyone tell me how to do it?

  • I suggest not using a controller, but a simple php file.

1 answer

0

The error seems to be in the way you call the script from the command line. According to the manual, you need to navigate to the project folder and run the index.php, passing to it controller and action:

cd /home/user/public_html/caminho_completo/application/
/caminho-do-php/php index.php cron index
                               |     |
                               |   action
                          controller

Browser other questions tagged

You are not signed in. Login or sign up in order to post.