I have a file named cron.php that exists in the application/controllers/admin directory in my CodeIgniter project.
From what I understand, the correct cron command to perform the “test” method in the cron.php file in cPanel would be:
/opt/php56/bin/php /home4/username/public_html/index.php cron test
However, the cron.php is in an admin folder in the controllers folder. Does that mean I have to do something like:
/opt/php56/bin/php /home4/username/public_html/index.php admin/cron test
How would I go about doing this?
2
Answers
Running a php script using the php bin does no thing to do with the framework you are using. It is just a script to execute.
This means, to run correctly your script in the cron, you need to give it the absolute path to it regardless your website or the framework you are using.
So if the file is physically located in /data/site/public_html/cron.php, this is the path you need to give to cron
If your cron runs the script as a url, then you need to give the url
As code under Codeigniter cannot be executed directly, as we will be having no direct access statement at top of every file.
you can use as follows
* * * * * /usr/bin/curl https://www.example.com/controller/function