[Solved] php session doesn’t work in cli


You have to search and read online articles before asking question in stackoverflow.
there are even same questions on stack.

yes thats true , PHP sessions are mainly created to be used with cgi SAPI, and as I know there is no use for php sessions with CLI SAPI.
and the reason is simple ,
http is stateless and we use cookie and session to remember user on server and track his/her actions.
but in console , why you need session at all???

consider that when running php in console there is no browser thhere is no http request, so there is no http header, so there is no http COOKIE header .

if you need a storage to be available to different php processes which are (CLI SAPI)
you can use database for this purpose.
but still if you insist on using php session for any reason,
take a look at here :

Is it possible to read cookie/session value while executing PHP5 script through command prompt?

1

solved php session doesn’t work in cli