Title: PHP Warning: session_start(): Failed to read session data: user
Last modified: January 26, 2023

---

# PHP Warning: session_start(): Failed to read session data: user

 *  Resolved [StevenP94](https://wordpress.org/support/users/stevenp94/)
 * (@stevenp94)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/php-warning-session_start-failed-to-read-session-data-user/)
 * Hi, digging in my logs while looking for performance optimization, I found a 
   lot of this:
   `PHP Warning: session_start(): Failed to read session data: user(
   path: /var/lib/php/sessions)`
 * After a lot of searches I found that this message could be caused from a read
   operation that returns null instead of empty string, so I made a workaround:
 * I’ve changed line 74 of wp-native-php-sessions/inc/class-session-handler.php 
   from
 * `return $session->get_data();`
 * to
 * `return $session->get_data() ?: '';`
 * Is this correct? There is a better way to solve this problem?

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Plugin Contributor [Chris Reynolds](https://wordpress.org/support/users/jazzs3quence/)
 * (@jazzs3quence)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/php-warning-session_start-failed-to-read-session-data-user/#post-16411775)
 * That looks valid to me. Are you able to confirm whether that solved the `seesion_start`
   error log messages?
 *  Thread Starter [StevenP94](https://wordpress.org/support/users/stevenp94/)
 * (@stevenp94)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/php-warning-session_start-failed-to-read-session-data-user/#post-16411787)
 * Yes, it seems so
 *  Plugin Contributor [Chris Reynolds](https://wordpress.org/support/users/jazzs3quence/)
 * (@jazzs3quence)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/php-warning-session_start-failed-to-read-session-data-user/#post-16411798)
 * Thanks for confirming. Proposed fix looks good to me, I will work on getting 
   this added to the plugin. Thanks for the report!
 *  Plugin Contributor [Chris Reynolds](https://wordpress.org/support/users/jazzs3quence/)
 * (@jazzs3quence)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/php-warning-session_start-failed-to-read-session-data-user/#post-16434896)
 * [@stevenp94](https://wordpress.org/support/users/stevenp94/)
 * Circling back to this, I am unable to reproduce the issue. Can you tell me about
   your environment? What version of PHP are you running? Is this a local environment(
   if so, what are you using for local dev?) or is this happening on a remote host?
 *  Thread Starter [StevenP94](https://wordpress.org/support/users/stevenp94/)
 * (@stevenp94)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/php-warning-session_start-failed-to-read-session-data-user/#post-16436292)
 * My environment:
   Apache/2.4.41 (Ubuntu)PHP 7.4.3WordPress 6.1.1
 * This happens on remote host, probably when someone try to get access and is not
   authorized (security drop the connection).
 * $session->get_data() returns null but $session is not null.
   I think that my solution
   can be a ‘safety’ change that increase the code solidity, just don’t know if 
   there is something better, I’m not so experienced in PHP
 * Thanks for your time
 *  Plugin Contributor [Chris Reynolds](https://wordpress.org/support/users/jazzs3quence/)
 * (@jazzs3quence)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/php-warning-session_start-failed-to-read-session-data-user/#post-16437777)
 * Cool cool. This helps. I agree it’s probably a good thing to fail gracefully,
   I just wanted to make sure I understood the context.
 *  Plugin Contributor [Chris Reynolds](https://wordpress.org/support/users/jazzs3quence/)
 * (@jazzs3quence)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/php-warning-session_start-failed-to-read-session-data-user/#post-16445653)
 * This will go out in the next update. Thanks for the report!
 *  Thread Starter [StevenP94](https://wordpress.org/support/users/stevenp94/)
 * (@stevenp94)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/php-warning-session_start-failed-to-read-session-data-user/#post-16447013)
 * You’re welcome!

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘PHP Warning: session_start(): Failed to read session data: user’ is closed
to new replies.

 * ![](https://ps.w.org/wp-native-php-sessions/assets/icon-256x256.png?rev=3411177)
 * [Native PHP Sessions](https://wordpress.org/plugins/wp-native-php-sessions/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-native-php-sessions/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-native-php-sessions/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-native-php-sessions/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-native-php-sessions/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-native-php-sessions/reviews/)

 * 8 replies
 * 2 participants
 * Last reply from: [StevenP94](https://wordpress.org/support/users/stevenp94/)
 * Last activity: [3 years, 4 months ago](https://wordpress.org/support/topic/php-warning-session_start-failed-to-read-session-data-user/#post-16447013)
 * Status: resolved