Welcome Guest, Not a member yet? Register   Sign In
Problem with CLI script routing or execution
#3

(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 

PHP Code:
// example
$routes->cli('cronjob/(:segment)''Cronjob::cliMessage/$1'); 

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
If you use Auto Routing, skip this.

(04-22-2025, 07:10 AM)warcooft Wrote: then run

Code:
php index.php cronjob codeigniter
// output: Hello codeigniter!

Also, your method is cliMessage not cliMAssage

See https://codeigniter.com/user_guide/cli/c...ello-world

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' => [
                '/',
                'user/login',
                'cli/cronjob/message']]

After this fix the method is corrected invoked.
I leave this post as it could be useful for other users.

Thank you
Reply


Messages In This Thread
RE: Problem with CLI script output - by warcooft - 04-22-2025, 07:10 AM
Problem with CLI script routing or execution - by massimiliano1.mancini - 04-22-2025, 09:11 AM



Theme © iAndrew 2016 - Forum software by © MyBB