![]() |
04-22-2025, 05:34 AM
(This post was last modified: 04-22-2025, 10:09 AM by massimiliano1.mancini.)
Hi All,
I'm trying to add some cron scheduled jobs to my site. I've started with a simple controller: PHP Code: <?php When I call it in my public directory Code: php index.php CLI/cronjob message no output is showed. The index.php and routing are executed for sure, infact if I make some mistakes on porpouse, they are showed. For example, this is the output of the following command Code: PS C:\develop\horizon\public> php index.php CLI/cronjob mAssage Any help is appreciated.
First, you have to define a route in app/Config/Routes.php
PHP Code: // example then run Code: php index.php cronjob codeigniter Also, your method is cliMessage not cliMAssage See https://codeigniter.com/user_guide/cli/c...ello-world
@xxxx[{::::::::::::::::::::::::::::::::>
04-22-2025, 09:11 AM
(This post was last modified: 04-22-2025, 10:32 AM by massimiliano1.mancini.)
Thank you for the reply.
(04-22-2025, 07:10 AM)warcooft Wrote: First, you have to define a route in app/Config/Routes.php I'm using Auto Route Improved, and according to the official guide, defining explicit routes like this isn’t necessary in my case: Quote:Define a Route (04-22-2025, 07:10 AM)warcooft Wrote: then run As you noticed, I intentionally used cliMAssage in the second example just to show that the framework is responding correctly. In the actual test, I use cliMessage as expected. I also tried using CLI library commands like CLI::print, but haven't had success with that either. EDIT: I've conducted further investigation and found that the cliMessage method in the Cronjob controller is not being called at all. I ran a debug session and set a breakpoint on the output line within the cliMessage method, and I confirmed that this point is never reached. For this reason, I'm updating the topic title, as the missing output is merely a consequence of a prior issue: the method doesn't appear to be invoked correctly in the first place. EDIT2: Solved! The problem was that I forgot to update the Config/Filters.php file in order to exclude the cli/cronjob/message path from mandatory authentication Code: 'auth' => ['except' => [ After this fix the method is corrected invoked. I leave this post as it could be useful for other users. Thank you
AFAIK, creating controllers and routes are not really necessary unless you want to expose some kind of RESTful service.
In my case I developed a bunch of 'Command's in App\Commands that can be run by both spark and any CRON job. It just works: PHP Code: <?php CodeIgniter Wizard (CRUD code generator for Mac) instantly scaffolds Bootstrap-based web applications with an administrative interface (admin templates include Bootstrap5) |
Welcome Guest, Not a member yet? Register Sign In |