0

I'm using symfony 4, What does error stands for ?

Warning: SessionHandler::read(): open(/var/lib/php/sessions/sess_634q91mh896b6aa4jpjvlihmar, O_RDWR) failed: Permission denied (13)

2 Answers2

1

When a user logs into a Symfony application, session information is stored on the web server. By default Symfony uses the native PHP session mechanism, storing session info in a file in /var/lib/php/sessions/ on Linux systems. Your error message is output by PHP and means it got a permissions error creating or re-opening a session file.

The error appears only intermittently because PHP removes old session files randomly about every 1/100th or 1/1000th page load. (On some Linux variants, old session files are removed by a cron job instead.)

https://symfony.com/doc/current/session.html says: "some session expiration related options may not work as expected if other applications that write to the same directory have short max lifetime settings."

Try to avoid having multiple processes writing to the same sessions directory. I think I got the error message because both an Apache web server and php bin/console server:start were running at the same time. One process may have removed the other process's session file.

See PHP manual and Symfony manual for how to configure writing to separate directories. For example, I changed {Symfony directory}/config/packages/framework.yaml:

# Enables session support. Note that the session will ONLY be started if you read or write from it.
# Remove or comment this section to explicitly disable session support.
session:
    # handler_id: ~
    cookie_secure: auto
    cookie_samesite: lax
    handler_id: 'session.handler.native_file'
    save_path: '%kernel.project_dir%/var/sessions/%kernel.environment%'
    gc_probability: 100  # Run garbage collection always for 
    gc_divisor: 100      # investigating this problem only.

Another possibility is a problem in your Symfony code can cause the error message. The Symfony documentation says not to call the PHP session functions like session_start() directly since Symfony classes call them. A bug in my code caused an exception which I speculate caused the error message.

Related stack overflow questions: cleanup-php-session-files and how-does-php-know-when-to-delete-a-session

For those familiar with C code, see the PHP interpreter source code line that prints the error here

Hope this helps!

Brent Pfister
  • 495
  • 6
  • 14
0

Not related to symfony 4, but you have to fix permissions in your /var/lib/php/sessions/ directory

Fabien Papet
  • 2,244
  • 2
  • 25
  • 52