PHP cli session warnings

Is it possible to disable session warnings displayed when php cli script starts? Without modifying php.ini, of course. I need to have the clean output of this script. The script does not run as Apache or Root. Session.auto_start is included in php.ini.

I have the following errors:

PHP Warning:  Unknown: open(/var/lib/php/session/sess_p6tpcdkpupelvho22qrkm699g4, O_RDWR) failed: Permission denied (13) in Unknown on line 0
PHP Warning:  Unknown: open(/var/lib/php/session/sess_p6tpcdkpupelvho22qrkm699g4, O_RDWR) failed: Permission denied (13) in Unknown on line 0

Thanks in advance!

+3
source share
1 answer

Simple enough, don't try to open a session in CLI mode. It will not work for several reasons. This way you could do 2 things (depending on how dirty the hack you wanted):

if (!isset($argc)) {
    //Not from CLI
    session_start();
}

Or, set the session path to something writable (for example, /tmp) if via cli:

if (isset($argc)) {
    session_save_path('/tmp');
}

(error_reporting(0)), , - ... @ ( , , , )

+7

Source: https://habr.com/ru/post/1781452/


All Articles