Welcome Guest, Not a member yet? Register   Sign In
Codeigniter Tasks do not work with cronjob
#1

Hi, I have a question.
Firstly, this package work fine if we run manually from terminal. but when i implement it in cron its like php spark bla:bla do nothing. I can not reproduce any errors in cron.
my command in cron: * * * * * cd /Applications/MAMP/htdocs/projects/cosmos && touch taskstarting.php && php spark tasks:run && touch taskstopping.php >> /dev/null 2>&1
I can see taskstarting.php inside my project. but, I can not see taskstopping.php inside my project that indicated php spark do nothing in cron.
Let me know how to achieve this, Thanks in advance.
Reply
#2

(07-11-2024, 06:25 PM)heruii Wrote: Hi, I have a question.
Firstly, this package work fine if we run manually from terminal. but when i implement it in cron its like php spark bla:bla do nothing. I can not reproduce any errors in cron.
my command in cron: * * * * * cd /Applications/MAMP/htdocs/projects/cosmos && touch taskstarting.php && php spark tasks:run && touch taskstopping.php >> /dev/null 2>&1
I can see taskstarting.php inside my project. but, I can not see taskstopping.php inside my project that indicated php spark do nothing in cron.
Let me know how to achieve this, Thanks in advance.

I presume
Code:
php spark tasks:run 
  works outside of cron.
Reply
#3

Try
Code:
* * * * * cd /Applications/MAMP/htdocs/projects/cosmos && php spark tasks:run >> cron.log 2>&1

and see the log file.
Reply
#4

Hi,
Some of the example cron statements in the CI documentation can be misleading especially where hosted and shared hosting environments are concerned, but then they are examples. Certainly in my case (shared hosting with cPanel), CI examples look more like Terminal commands rather than a scheduled CRON.

For example via Terminal I would cd (change directory to my target folder) then execute with: php spark command:run.
While a scheduled CRON command line would look more like /hosted/path/to/php /home/myserver/myfolder/spark command:run.

My shared hosting provider (using cPanel) recomended prepending all of my cron jobs with CRON_MODE=1, due to it's specific php configuration and use.
I also have to reference where (on the server) the php is being call from, directly in the command line.


For example, where my shared hosted environmet is

Code:
/home/myserver/myfolder/mydomain.com


where myfolder stores my codigniter files (app, public, system, etc), and mydomain.com is my public folder (renamed).


Therefore to get a CRON to call a named route (note the space after index.php)
Code:
CRON_MODE=1 /hosted/path/to/php /home/myserver/myfolder/mydomain.com/index.php namedroute


To get CRON call a command (note the path to the file location, exclude php and NO space before spark)

Code:
CRON_MODE=1 /hosted/path/to/php /home/myserver/myfolder/spark command:run


Note: I have have a CRON running every minute executing Tasks
Code:
CRON_MODE=1 /hosted/path/to/php /home/myserver/myfolder/spark Tasks:run



I hope this helps!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB