Welcome Guest, Not a member yet? Register   Sign In
codeigniter 4.1.8 - Session: Initialization under CLI aborted.
#1

(This post was last modified: 02-11-2022, 07:43 AM by magu.)

Hi,
I get this error "Session: Initialization under CLI aborted." in a log file, when I try to call a controller (php public/index.php tools) via cli in CI development environment. I want to allow a cronjob to call a specific route to save some data in mysql.

This is the example I used: https://codeigniter.com/user_guide/cli/c...ello-world

After debugging for a while, I changed CI_ENVIRONMENT = development to CI_ENVIRONMENT = testing in the .env file and it worked. I was able to call the route via cli.

Why is calling a route via cli only allowed in testing mode? Is this a bug or is this the way it should work?

I am new to codeigniter. I hope someone can explain it. Thanks.

Greetings, magu
Reply
#2

Hi!

1) Do not ever use the "testing" environment in your projects. It is internal to the development team for our unit testing.

2) By definition, the CLI version of PHP is a stand-alone process. It's not tied in any way to a web-server, or an HTTP session, or anything like that. Consequently, the concept of GET/POST/session/cookie variables is meaningless in CLI PHP. (https://bytes.com/topic/php/answers/4846...php-script). In short, you really can't access Session in CLI since PHP itself allows it only in HTTP (browser) context.
Reply
#3

(This post was last modified: 11-30-2023, 04:15 AM by engel.)

Maybe this is too late but in case anyone might come across to this problem, "Session: Initialization under CLI aborted." implies that your application is autoloading the session library while you are using CLI. @paulbalandan is right that you can't really access Session in CLI. In my case, I needed the Session to be auto-loaded, so I had to exclude the controller that was used for CLI access from the Before Filters. Hope this helps and still relevant.
Reply
#4

(This post was last modified: 01-24-2024, 03:04 PM by Gary.)

(11-30-2023, 04:14 AM)engel Wrote: Maybe this is too late but in case anyone might come across to this problem, "Session: Initialization under CLI aborted." implies that your application is  autoloading the session library while you are  using CLI. @paulbalandan is right that you can't really access Session in CLI. In my case, I needed the Session to be auto-loaded, so I had to exclude the controller that was used for CLI access from the Before Filters. Hope this helps and still relevant.

You're brilliant Engel!  That's an excellently elegant work-around!  Thanks.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB