3
votes

Is there any possibility to disable session warnings being displayed when php cli script is run? Without modyfing php.ini of course. I need to have clean output of this script. Script is not run as Apache or Root. In php.ini there is an session.auto_start enabled.

I've got 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!

1
Who are you running this as? Are you using sessions in your script? - Pekka

1 Answers

7
votes

Quite simple, don't try to open the session in CLI mode. It won't work for multiple reasons. So, you could do 2 things (depending on how "dirty" of a hack you wanted):

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

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

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

But I'd suggest not suppressing all errors (error_reporting(0)) because it will make debugging and telling when something went wrong so much harder... I'd also suggest not using @ to suppress errors (simply because I think you should avoid errors instead of suppressing them)