<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>[PHP] Customized Session Handler can not work for PHP 5.1.6 and CentOS 5.5</title>
        <description> Hi, All,

System: CentOS 5.5; PHP version is 5.1.6.

I met a strange problem associate with session_save_handler in current 
environment(The same code can work well in my local windows platform and 
ubuntu system).

I just want to use a customized session save handler to be triggered, so 
that I can call my own logic to handling the session. The testing in 
local is pretty great but when migration to the VPS, it bring me the 
following error:

Fatal error: session_start() [&amp;lt;a 
href='function.session-start'&amp;gt;function.session-start&amp;lt;/a&amp;gt;]: Failed to 
initialize storage module: user (path: /tmp)


The default value for session save handler and session save path in 
php.ini are:

session.save_handler = files
session.save_path = &amp;quot;/tmp&amp;quot;
session.name = PHPSESSID


And the bottom are the code for the session handler. I first called 
ob_start(), and after calling session::init(), I called session_start(). 
Then the fatal error happen. It did not trigger any function in the 
&amp;quot;session&amp;quot; class.

I tried change the php.ini from session.save_handler = user, but the 
error remains. And I found no matter what session.save_handler type is, 
after calling session_set_save_handler(), the session.save_handler will 
always automatically changed to 'user', that's why the Fatal error info 
shows user (path: /tmp).

Can anybody help me out for such error? I was stuck by this issue for 
more than 2 days, but still haven't get any clue!

You can view more details from stackoverflow if you want. Here is the link:
http://stackoverflow.com/questions/8845924/session-set-save-handler-class-for-database-not-working


&amp;lt;?php
class session
{
   public static function init()
   {
     session_set_save_handler('session::open', 'session::close', 
'session::read', 'session::write', 'session::destroy', 'session::gc');
   }

   public static function open($save_path, $session_name)
   {
      if (!is_dir($save_path)) {
             mkdir($save_path, 0777);
      }
     return true;
   }

   public static function close()
   {
     return true;
   }

   public static function read($sid)
   {
     global $db, $user;
     register_shutdown_function('session_write_close');
     if (!isset($_COOKIE[session_name()])) {
       $user = anonymousUser($sid);
       return '';
     }
     $result = $db-&amp;gt;query('SELECT s.data as session_data, s.* , u.* FROM 
users u INNER JOIN sessions s ON u.uid = s.uid WHERE s.sid = &amp;quot;' . 
$db-&amp;gt;escape($sid) .
       '&amp;quot; AND timestamp &amp;gt;= ' . $db-&amp;gt;escape(TIMESTAMP - 
Bl_Config::get('session.lifetime', 10800)));
     $user = $result-&amp;gt;row();

     if ($user) {
       $data = $user-&amp;gt;session_data;
       unset($user-&amp;gt;passwd, $user-&amp;gt;session_data);
       if ($user-&amp;gt;uid &amp;gt; 0 &amp;amp;&amp;amp; $user-&amp;gt;status == 1) {
         $userInstance = User_Model::getInstance();
         $user-&amp;gt;roles = $userInstance-&amp;gt;getUserRoles($user-&amp;gt;uid);
         $user-&amp;gt;roles[] = User_Model::ROLE_AUTHENTICATED_USER;
         $user-&amp;gt;permissions = array();
         $user-&amp;gt;data = (isset($user-&amp;gt;data) &amp;amp;&amp;amp; $user-&amp;gt;data) ? 
unserialize($user-&amp;gt;data) : array();
         foreach ($user-&amp;gt;roles as $rid) {
           $user-&amp;gt;permissions = array_merge($user-&amp;gt;permissions, 
$userInstance-&amp;gt;getRolePermissions($rid));
         }
         $user-&amp;gt;permissions = array_unique($user-&amp;gt;permissions);
       } else {
         $user = anonymousUser($sid);
       }
       return $data;
     } else {
       $user = anonymousUser($sid);
       return '';
     }
   }

   public static function write($sid, $data)
   {
     global $db, $user;
     if (!isset($user) || ($user-&amp;gt;uid == 0 &amp;amp;&amp;amp; 
empty($_COOKIE[session_name()]) &amp;amp;&amp;amp; empty($data))) {
       return true;
     }
     $uri = '/' . Bl_Core::getUri();
     $db-&amp;gt;exec('UPDATE sessions SET uid = ' . $db-&amp;gt;escape($user-&amp;gt;uid) . 
', ip = &amp;quot;' . $db-&amp;gt;escape(ipAddress()) .
       '&amp;quot;, uri = &amp;quot;' . $db-&amp;gt;escape($uri) . '&amp;quot;, data = &amp;quot;' . 
$db-&amp;gt;escape($data) . '&amp;quot;, timestamp = ' .
       $db-&amp;gt;escape(TIMESTAMP) . ' WHERE sid = &amp;quot;' . $db-&amp;gt;escape($sid) . '&amp;quot;');
     if (!$db-&amp;gt;affected()) {
       $db-&amp;gt;exec('INSERT IGNORE INTO sessions (sid, uid, ip, uri, data, 
timestamp) VALUES (&amp;quot;' . $db-&amp;gt;escape($sid) .
         '&amp;quot;, ' . $db-&amp;gt;escape($user-&amp;gt;uid) . ', &amp;quot;' . 
$db-&amp;gt;escape(ipAddress()) . '&amp;quot;, &amp;quot;' . $db-&amp;gt;escape($uri) . '&amp;quot;, &amp;quot;' .
         $db-&amp;gt;escape($data) . '&amp;quot;, ' . $db-&amp;gt;escape(TIMESTAMP) . ')');
     }
     return true;
   }

   public static function destroy($sid)
   {
     global $db;
     $db-&amp;gt;exec('DELETE FROM sessions WHERE sid = &amp;quot;' . $db-&amp;gt;escape($sid) 
... '&amp;quot;');
     return true;
   }

   public static function gc($lifetime)
   {
     global $db;
     $db-&amp;gt;exec('DELETE FROM sessions WHERE timestamp &amp;lt; ' . 
$db-&amp;gt;escape(TIMESTAMP - Bl_Config::get('session.lifetime', 10800)));
     return true;
   }

   public static function count($timestamp = 0, $hasAnonymous = true)
   {
     global $db;
     if (!$hasAnonymous) {
       $cond = ' AND uid &amp;gt; 0';
     } else {
       $cond = '';
     }
     $result = $db-&amp;gt;query('SELECT COUNT(0) FROM sessions WHERE timestamp 
 &amp;gt; ' . $timestamp . $cond);
     return $result-&amp;gt;one();
   }
}





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php</description>
        <link>http://www.serverphorums.com/read.php?8,479721,479721#msg-479721</link>
        <lastBuildDate>Sun, 26 May 2013 09:16:53 +0200</lastBuildDate>
        <generator>Phorum 5.2.18</generator>
        <item>
            <guid>http://www.serverphorums.com/read.php?8,479721,480627#msg-480627</guid>
            <title>Re: [PHP] Customized Session Handler can not work for PHP 5.1.6 andCentOS 5.5</title>
            <link>http://www.serverphorums.com/read.php?8,479721,480627#msg-480627</link>
            <description><![CDATA[ Hi, Tommy,<br />
<br />
Thank you!<br />
<br />
You are great that after all other methods tried, I finally upgrade my <br />
php version, and found it's worked!!!<br />
<br />
The CentOS VPS use Cent OS 5.5 and PHP 5.1.6 as default, but it has <br />
problem for supporting custom session save handlers. It's weird that no <br />
one and no doc mentioned this!!!<br />
<br />
My suggestions is using PHP Version 5.2.6 or later to using such feature.<br />
<br />
Mingda<br />
<br />
On 2012/4/16 10:45, Tommy Pham wrote:<br />
&gt; On Sat, Apr 14, 2012 at 9:27 AM, Mingda&lt;mingdadev@gmail.com&gt;  wrote:<br />
&gt;&gt; Hi, All,<br />
&gt;&gt;<br />
&gt;&gt; System: CentOS 5.5; PHP version is 5.1.6.<br />
&gt;&gt;<br />
&gt;&gt; I met a strange problem associate with session_save_handler in current<br />
&gt;&gt; environment(The same code can work well in my local windows platform and<br />
&gt;&gt; ubuntu system).<br />
&gt;&gt;<br />
&gt;<br />
&gt; This is your clue on how to fix.  What version of PHP are on Windows<br />
&gt; and Ubuntu?  If different, perhaps upgrade your CentOS' PHP?  If the<br />
&gt; same exact version on all 3 OSes, then consult CentOS :).<br />
&gt;<br />
&gt; HTH,<br />
&gt; Tommy<br />
<br />
<br />
-- <br />
PHP General Mailing List (http://www.php.net/)<br />
To unsubscribe, visit: <a href="http://www.php.net/unsub.php" target="_blank"  rel="nofollow">http://www.php.net/unsub.php</a>]]></description>
            <dc:creator>Mingda</dc:creator>
            <category>php-general</category>
            <pubDate>Tue, 17 Apr 2012 08:00:03 +0200</pubDate>
        </item>
        <item>
            <guid>http://www.serverphorums.com/read.php?8,479721,479788#msg-479788</guid>
            <title>[PHP] Re: Customized Session Handler can not work for PHP 5.1.6 and CentOS5.5</title>
            <link>http://www.serverphorums.com/read.php?8,479721,479788#msg-479788</link>
            <description><![CDATA[ Sorry, wrong link provided, correct link is:<br />
<br />
<a href="http://stackoverflow.com/questions/10150296/cant-make-custom-session-save-handler-workno-registered-method-called-in-cent#comment13018050_10150327" target="_blank"  rel="nofollow">http://stackoverflow.com/questions/10150296/cant-make-custom-session-save-handler-workno-registered-method-called-in-cent#comment13018050_10150327</a> <br />
<br />
<br />
<br />
<br />
<br />
On 2012/4/15 0:27, Mingda wrote:<br />
&gt; Hi, All,<br />
&gt;<br />
&gt; System: CentOS 5.5; PHP version is 5.1.6.<br />
&gt;<br />
&gt; I met a strange problem associate with session_save_handler in current<br />
&gt; environment(The same code can work well in my local windows platform and<br />
&gt; ubuntu system).<br />
&gt;<br />
&gt; I just want to use a customized session save handler to be triggered, so<br />
&gt; that I can call my own logic to handling the session. The testing in<br />
&gt; local is pretty great but when migration to the VPS, it bring me the<br />
&gt; following error:<br />
&gt;<br />
&gt; Fatal error: session_start() [&lt;a<br />
&gt; href='function.session-start'&gt;function.session-start&lt;/a&gt;]: Failed to<br />
&gt; initialize storage module: user (path: /tmp)<br />
&gt;<br />
&gt;<br />
&gt; The default value for session save handler and session save path in<br />
&gt; php.ini are:<br />
&gt;<br />
&gt; session.save_handler = files<br />
&gt; session.save_path = &quot;/tmp&quot;<br />
&gt; session.name = PHPSESSID<br />
&gt;<br />
&gt;<br />
&gt; And the bottom are the code for the session handler. I first called<br />
&gt; ob_start(), and after calling session::init(), I called session_start().<br />
&gt; Then the fatal error happen. It did not trigger any function in the<br />
&gt; &quot;session&quot; class.<br />
&gt;<br />
&gt; I tried change the php.ini from session.save_handler = user, but the<br />
&gt; error remains. And I found no matter what session.save_handler type is,<br />
&gt; after calling session_set_save_handler(), the session.save_handler will<br />
&gt; always automatically changed to 'user', that's why the Fatal error info<br />
&gt; shows user (path: /tmp).<br />
&gt;<br />
&gt; Can anybody help me out for such error? I was stuck by this issue for<br />
&gt; more than 2 days, but still haven't get any clue!<br />
&gt;<br />
&gt; You can view more details from stackoverflow if you want. Here is the link:<br />
&gt; <a href="http://stackoverflow.com/questions/8845924/session-set-save-handler-class-for-database-not-working" target="_blank"  rel="nofollow">http://stackoverflow.com/questions/8845924/session-set-save-handler-class-for-database-not-working</a><br />
&gt;<br />
&gt;<br />
&gt;<br />
&gt; &lt;?php<br />
&gt; class session<br />
&gt; {<br />
&gt; public static function init()<br />
&gt; {<br />
&gt; session_set_save_handler('session::open', 'session::close',<br />
&gt; 'session::read', 'session::write', 'session::destroy', 'session::gc');<br />
&gt; }<br />
&gt;<br />
&gt; public static function open($save_path, $session_name)<br />
&gt; {<br />
&gt; if (!is_dir($save_path)) {<br />
&gt; mkdir($save_path, 0777);<br />
&gt; }<br />
&gt; return true;<br />
&gt; }<br />
&gt;<br />
&gt; public static function close()<br />
&gt; {<br />
&gt; return true;<br />
&gt; }<br />
&gt;<br />
&gt; public static function read($sid)<br />
&gt; {<br />
&gt; global $db, $user;<br />
&gt; register_shutdown_function('session_write_close');<br />
&gt; if (!isset($_COOKIE[session_name()])) {<br />
&gt; $user = anonymousUser($sid);<br />
&gt; return '';<br />
&gt; }<br />
&gt; $result = $db-&gt;query('SELECT s.data as session_data, s.* , u.* FROM<br />
&gt; users u INNER JOIN sessions s ON u.uid = s.uid WHERE s.sid = &quot;' .<br />
&gt; $db-&gt;escape($sid) .<br />
&gt; '&quot; AND timestamp &gt;= ' . $db-&gt;escape(TIMESTAMP -<br />
&gt; Bl_Config::get('session.lifetime', 10800)));<br />
&gt; $user = $result-&gt;row();<br />
&gt;<br />
&gt; if ($user) {<br />
&gt; $data = $user-&gt;session_data;<br />
&gt; unset($user-&gt;passwd, $user-&gt;session_data);<br />
&gt; if ($user-&gt;uid &gt; 0 &amp;&amp; $user-&gt;status == 1) {<br />
&gt; $userInstance = User_Model::getInstance();<br />
&gt; $user-&gt;roles = $userInstance-&gt;getUserRoles($user-&gt;uid);<br />
&gt; $user-&gt;roles[] = User_Model::ROLE_AUTHENTICATED_USER;<br />
&gt; $user-&gt;permissions = array();<br />
&gt; $user-&gt;data = (isset($user-&gt;data) &amp;&amp; $user-&gt;data) ?<br />
&gt; unserialize($user-&gt;data) : array();<br />
&gt; foreach ($user-&gt;roles as $rid) {<br />
&gt; $user-&gt;permissions = array_merge($user-&gt;permissions,<br />
&gt; $userInstance-&gt;getRolePermissions($rid));<br />
&gt; }<br />
&gt; $user-&gt;permissions = array_unique($user-&gt;permissions);<br />
&gt; } else {<br />
&gt; $user = anonymousUser($sid);<br />
&gt; }<br />
&gt; return $data;<br />
&gt; } else {<br />
&gt; $user = anonymousUser($sid);<br />
&gt; return '';<br />
&gt; }<br />
&gt; }<br />
&gt;<br />
&gt; public static function write($sid, $data)<br />
&gt; {<br />
&gt; global $db, $user;<br />
&gt; if (!isset($user) || ($user-&gt;uid == 0 &amp;&amp; empty($_COOKIE[session_name()])<br />
&gt; &amp;&amp; empty($data))) {<br />
&gt; return true;<br />
&gt; }<br />
&gt; $uri = '/' . Bl_Core::getUri();<br />
&gt; $db-&gt;exec('UPDATE sessions SET uid = ' . $db-&gt;escape($user-&gt;uid) . ', ip<br />
&gt; = &quot;' . $db-&gt;escape(ipAddress()) .<br />
&gt; '&quot;, uri = &quot;' . $db-&gt;escape($uri) . '&quot;, data = &quot;' . $db-&gt;escape($data) .<br />
&gt; '&quot;, timestamp = ' .<br />
&gt; $db-&gt;escape(TIMESTAMP) . ' WHERE sid = &quot;' . $db-&gt;escape($sid) . '&quot;');<br />
&gt; if (!$db-&gt;affected()) {<br />
&gt; $db-&gt;exec('INSERT IGNORE INTO sessions (sid, uid, ip, uri, data,<br />
&gt; timestamp) VALUES (&quot;' . $db-&gt;escape($sid) .<br />
&gt; '&quot;, ' . $db-&gt;escape($user-&gt;uid) . ', &quot;' . $db-&gt;escape(ipAddress()) . '&quot;,<br />
&gt; &quot;' . $db-&gt;escape($uri) . '&quot;, &quot;' .<br />
&gt; $db-&gt;escape($data) . '&quot;, ' . $db-&gt;escape(TIMESTAMP) . ')');<br />
&gt; }<br />
&gt; return true;<br />
&gt; }<br />
&gt;<br />
&gt; public static function destroy($sid)<br />
&gt; {<br />
&gt; global $db;<br />
&gt; $db-&gt;exec('DELETE FROM sessions WHERE sid = &quot;' . $db-&gt;escape($sid) .. '&quot;');<br />
&gt; return true;<br />
&gt; }<br />
&gt;<br />
&gt; public static function gc($lifetime)<br />
&gt; {<br />
&gt; global $db;<br />
&gt; $db-&gt;exec('DELETE FROM sessions WHERE timestamp &lt; ' .<br />
&gt; $db-&gt;escape(TIMESTAMP - Bl_Config::get('session.lifetime', 10800)));<br />
&gt; return true;<br />
&gt; }<br />
&gt;<br />
&gt; public static function count($timestamp = 0, $hasAnonymous = true)<br />
&gt; {<br />
&gt; global $db;<br />
&gt; if (!$hasAnonymous) {<br />
&gt; $cond = ' AND uid &gt; 0';<br />
&gt; } else {<br />
&gt; $cond = '';<br />
&gt; }<br />
&gt; $result = $db-&gt;query('SELECT COUNT(0) FROM sessions WHERE timestamp &gt; '<br />
&gt; . $timestamp . $cond);<br />
&gt; return $result-&gt;one();<br />
&gt; }<br />
&gt; }<br />
&gt;<br />
&gt;<br />
&gt;<br />
&gt;<br />
<br />
<br />
-- <br />
PHP General Mailing List (http://www.php.net/)<br />
To unsubscribe, visit: <a href="http://www.php.net/unsub.php" target="_blank"  rel="nofollow">http://www.php.net/unsub.php</a>]]></description>
            <dc:creator>Mingda</dc:creator>
            <category>php-general</category>
            <pubDate>Mon, 16 Apr 2012 08:40:01 +0200</pubDate>
        </item>
        <item>
            <guid>http://www.serverphorums.com/read.php?8,479721,479787#msg-479787</guid>
            <title>Re: [PHP] Customized Session Handler can not work for PHP 5.1.6 and CentOS 5.5</title>
            <link>http://www.serverphorums.com/read.php?8,479721,479787#msg-479787</link>
            <description><![CDATA[ Hi, Thanks, it's originally is /var/lib/php/session, I double it's <br />
privilege problem, so changed to /tmp.<br />
<br />
And I Followed your advice for setenforce off, but can't make it work.<br />
<br />
Mingda<br />
<br />
On 2012/4/16 14:13, Alain Williams wrote:<br />
&gt; On Sun, Apr 15, 2012 at 12:27:00AM +0800, Mingda wrote:<br />
&gt;&gt; Hi, All,<br />
&gt;&gt;<br />
&gt;&gt; System: CentOS 5.5; PHP version is 5.1.6.<br />
&gt;&gt;<br />
&gt;&gt; I met a strange problem associate with session_save_handler in current<br />
&gt;&gt; environment(The same code can work well in my local windows platform and<br />
&gt;&gt; ubuntu system).<br />
&gt;&gt;<br />
&gt;&gt; I just want to use a customized session save handler to be triggered, so<br />
&gt;&gt; that I can call my own logic to handling the session. The testing in<br />
&gt;&gt; local is pretty great but when migration to the VPS, it bring me the<br />
&gt;&gt; following error:<br />
&gt;&gt;<br />
&gt;&gt; Fatal error: session_start() [&lt;a<br />
&gt;&gt; href='function.session-start'&gt;function.session-start&lt;/a&gt;]: Failed to<br />
&gt;&gt; initialize storage module: user (path: /tmp)<br />
&gt;&gt;<br />
&gt;&gt;<br />
&gt;&gt; The default value for session save handler and session save path in<br />
&gt;&gt; php.ini are:<br />
&gt;&gt;<br />
&gt;&gt; session.save_handler = files<br />
&gt;&gt; session.save_path = &quot;/tmp&quot;<br />
&gt;&gt; session.name = PHPSESSID<br />
&gt;<br />
&gt; Try changing the path to /var/lib/php/session<br />
&gt;<br />
&gt; Are you being caught by selinux - try<br />
&gt; 	setenforce off<br />
&gt; and see if that makes it work.<br />
&gt;<br />
<br />
<br />
-- <br />
PHP General Mailing List (http://www.php.net/)<br />
To unsubscribe, visit: <a href="http://www.php.net/unsub.php" target="_blank"  rel="nofollow">http://www.php.net/unsub.php</a>]]></description>
            <dc:creator>Mingda</dc:creator>
            <category>php-general</category>
            <pubDate>Mon, 16 Apr 2012 08:40:01 +0200</pubDate>
        </item>
        <item>
            <guid>http://www.serverphorums.com/read.php?8,479721,479782#msg-479782</guid>
            <title>Re: [PHP] Customized Session Handler can not work for PHP 5.1.6 and CentOS 5.5</title>
            <link>http://www.serverphorums.com/read.php?8,479721,479782#msg-479782</link>
            <description><![CDATA[ On Sun, Apr 15, 2012 at 12:27:00AM +0800, Mingda wrote:<br />
&gt; Hi, All,<br />
&gt; <br />
&gt; System: CentOS 5.5; PHP version is 5.1.6.<br />
&gt; <br />
&gt; I met a strange problem associate with session_save_handler in current <br />
&gt; environment(The same code can work well in my local windows platform and <br />
&gt; ubuntu system).<br />
&gt; <br />
&gt; I just want to use a customized session save handler to be triggered, so <br />
&gt; that I can call my own logic to handling the session. The testing in <br />
&gt; local is pretty great but when migration to the VPS, it bring me the <br />
&gt; following error:<br />
&gt; <br />
&gt; Fatal error: session_start() [&lt;a <br />
&gt; href='function.session-start'&gt;function.session-start&lt;/a&gt;]: Failed to <br />
&gt; initialize storage module: user (path: /tmp)<br />
&gt; <br />
&gt; <br />
&gt; The default value for session save handler and session save path in <br />
&gt; php.ini are:<br />
&gt; <br />
&gt; session.save_handler = files<br />
&gt; session.save_path = &quot;/tmp&quot;<br />
&gt; session.name = PHPSESSID<br />
<br />
Try changing the path to /var/lib/php/session<br />
<br />
Are you being caught by selinux - try<br />
	setenforce off<br />
and see if that makes it work.<br />
<br />
-- <br />
Alain Williams<br />
Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.<br />
+44 (0) 787 668 0256  <a href="http://www.phcomp.co.uk/" target="_blank"  rel="nofollow">http://www.phcomp.co.uk/</a><br />
Parliament Hill Computers Ltd. Registration Information: <a href="http://www.phcomp.co.uk/contact.php" target="_blank"  rel="nofollow">http://www.phcomp.co.uk/contact.php</a><br />
#include &lt;std_disclaimer.h&gt;<br />
<br />
-- <br />
PHP General Mailing List (http://www.php.net/)<br />
To unsubscribe, visit: <a href="http://www.php.net/unsub.php" target="_blank"  rel="nofollow">http://www.php.net/unsub.php</a>]]></description>
            <dc:creator>Alain Williams</dc:creator>
            <category>php-general</category>
            <pubDate>Mon, 16 Apr 2012 08:20:04 +0200</pubDate>
        </item>
        <item>
            <guid>http://www.serverphorums.com/read.php?8,479721,479732#msg-479732</guid>
            <title>Re: [PHP] Customized Session Handler can not work for PHP 5.1.6 and CentOS 5.5</title>
            <link>http://www.serverphorums.com/read.php?8,479721,479732#msg-479732</link>
            <description><![CDATA[ On Sat, Apr 14, 2012 at 9:27 AM, Mingda &lt;mingdadev@gmail.com&gt; wrote:<br />
&gt; Hi, All,<br />
&gt;<br />
&gt; System: CentOS 5.5; PHP version is 5.1.6.<br />
&gt;<br />
&gt; I met a strange problem associate with session_save_handler in current<br />
&gt; environment(The same code can work well in my local windows platform and<br />
&gt; ubuntu system).<br />
&gt;<br />
<br />
This is your clue on how to fix.  What version of PHP are on Windows<br />
and Ubuntu?  If different, perhaps upgrade your CentOS' PHP?  If the<br />
same exact version on all 3 OSes, then consult CentOS :).<br />
<br />
HTH,<br />
Tommy<br />
<br />
-- <br />
PHP General Mailing List (http://www.php.net/)<br />
To unsubscribe, visit: <a href="http://www.php.net/unsub.php" target="_blank"  rel="nofollow">http://www.php.net/unsub.php</a>]]></description>
            <dc:creator>Tommy Pham</dc:creator>
            <category>php-general</category>
            <pubDate>Mon, 16 Apr 2012 04:50:02 +0200</pubDate>
        </item>
        <item>
            <guid>http://www.serverphorums.com/read.php?8,479721,479721#msg-479721</guid>
            <title>[PHP] Customized Session Handler can not work for PHP 5.1.6 and CentOS 5.5</title>
            <link>http://www.serverphorums.com/read.php?8,479721,479721#msg-479721</link>
            <description><![CDATA[ Hi, All,<br />
<br />
System: CentOS 5.5; PHP version is 5.1.6.<br />
<br />
I met a strange problem associate with session_save_handler in current <br />
environment(The same code can work well in my local windows platform and <br />
ubuntu system).<br />
<br />
I just want to use a customized session save handler to be triggered, so <br />
that I can call my own logic to handling the session. The testing in <br />
local is pretty great but when migration to the VPS, it bring me the <br />
following error:<br />
<br />
Fatal error: session_start() [&lt;a <br />
href='function.session-start'&gt;function.session-start&lt;/a&gt;]: Failed to <br />
initialize storage module: user (path: /tmp)<br />
<br />
<br />
The default value for session save handler and session save path in <br />
php.ini are:<br />
<br />
session.save_handler = files<br />
session.save_path = &quot;/tmp&quot;<br />
session.name = PHPSESSID<br />
<br />
<br />
And the bottom are the code for the session handler. I first called <br />
ob_start(), and after calling session::init(), I called session_start(). <br />
Then the fatal error happen. It did not trigger any function in the <br />
&quot;session&quot; class.<br />
<br />
I tried change the php.ini from session.save_handler = user, but the <br />
error remains. And I found no matter what session.save_handler type is, <br />
after calling session_set_save_handler(), the session.save_handler will <br />
always automatically changed to 'user', that's why the Fatal error info <br />
shows user (path: /tmp).<br />
<br />
Can anybody help me out for such error? I was stuck by this issue for <br />
more than 2 days, but still haven't get any clue!<br />
<br />
You can view more details from stackoverflow if you want. Here is the link:<br />
<a href="http://stackoverflow.com/questions/8845924/session-set-save-handler-class-for-database-not-working" target="_blank"  rel="nofollow">http://stackoverflow.com/questions/8845924/session-set-save-handler-class-for-database-not-working</a><br />
<br />
<br />
&lt;?php<br />
class session<br />
{<br />
   public static function init()<br />
   {<br />
     session_set_save_handler('session::open', 'session::close', <br />
'session::read', 'session::write', 'session::destroy', 'session::gc');<br />
   }<br />
<br />
   public static function open($save_path, $session_name)<br />
   {<br />
      if (!is_dir($save_path)) {<br />
             mkdir($save_path, 0777);<br />
      }<br />
     return true;<br />
   }<br />
<br />
   public static function close()<br />
   {<br />
     return true;<br />
   }<br />
<br />
   public static function read($sid)<br />
   {<br />
     global $db, $user;<br />
     register_shutdown_function('session_write_close');<br />
     if (!isset($_COOKIE[session_name()])) {<br />
       $user = anonymousUser($sid);<br />
       return '';<br />
     }<br />
     $result = $db-&gt;query('SELECT s.data as session_data, s.* , u.* FROM <br />
users u INNER JOIN sessions s ON u.uid = s.uid WHERE s.sid = &quot;' . <br />
$db-&gt;escape($sid) .<br />
       '&quot; AND timestamp &gt;= ' . $db-&gt;escape(TIMESTAMP - <br />
Bl_Config::get('session.lifetime', 10800)));<br />
     $user = $result-&gt;row();<br />
<br />
     if ($user) {<br />
       $data = $user-&gt;session_data;<br />
       unset($user-&gt;passwd, $user-&gt;session_data);<br />
       if ($user-&gt;uid &gt; 0 &amp;&amp; $user-&gt;status == 1) {<br />
         $userInstance = User_Model::getInstance();<br />
         $user-&gt;roles = $userInstance-&gt;getUserRoles($user-&gt;uid);<br />
         $user-&gt;roles[] = User_Model::ROLE_AUTHENTICATED_USER;<br />
         $user-&gt;permissions = array();<br />
         $user-&gt;data = (isset($user-&gt;data) &amp;&amp; $user-&gt;data) ? <br />
unserialize($user-&gt;data) : array();<br />
         foreach ($user-&gt;roles as $rid) {<br />
           $user-&gt;permissions = array_merge($user-&gt;permissions, <br />
$userInstance-&gt;getRolePermissions($rid));<br />
         }<br />
         $user-&gt;permissions = array_unique($user-&gt;permissions);<br />
       } else {<br />
         $user = anonymousUser($sid);<br />
       }<br />
       return $data;<br />
     } else {<br />
       $user = anonymousUser($sid);<br />
       return '';<br />
     }<br />
   }<br />
<br />
   public static function write($sid, $data)<br />
   {<br />
     global $db, $user;<br />
     if (!isset($user) || ($user-&gt;uid == 0 &amp;&amp; <br />
empty($_COOKIE[session_name()]) &amp;&amp; empty($data))) {<br />
       return true;<br />
     }<br />
     $uri = '/' . Bl_Core::getUri();<br />
     $db-&gt;exec('UPDATE sessions SET uid = ' . $db-&gt;escape($user-&gt;uid) . <br />
', ip = &quot;' . $db-&gt;escape(ipAddress()) .<br />
       '&quot;, uri = &quot;' . $db-&gt;escape($uri) . '&quot;, data = &quot;' . <br />
$db-&gt;escape($data) . '&quot;, timestamp = ' .<br />
       $db-&gt;escape(TIMESTAMP) . ' WHERE sid = &quot;' . $db-&gt;escape($sid) . '&quot;');<br />
     if (!$db-&gt;affected()) {<br />
       $db-&gt;exec('INSERT IGNORE INTO sessions (sid, uid, ip, uri, data, <br />
timestamp) VALUES (&quot;' . $db-&gt;escape($sid) .<br />
         '&quot;, ' . $db-&gt;escape($user-&gt;uid) . ', &quot;' . <br />
$db-&gt;escape(ipAddress()) . '&quot;, &quot;' . $db-&gt;escape($uri) . '&quot;, &quot;' .<br />
         $db-&gt;escape($data) . '&quot;, ' . $db-&gt;escape(TIMESTAMP) . ')');<br />
     }<br />
     return true;<br />
   }<br />
<br />
   public static function destroy($sid)<br />
   {<br />
     global $db;<br />
     $db-&gt;exec('DELETE FROM sessions WHERE sid = &quot;' . $db-&gt;escape($sid) <br />
... '&quot;');<br />
     return true;<br />
   }<br />
<br />
   public static function gc($lifetime)<br />
   {<br />
     global $db;<br />
     $db-&gt;exec('DELETE FROM sessions WHERE timestamp &lt; ' . <br />
$db-&gt;escape(TIMESTAMP - Bl_Config::get('session.lifetime', 10800)));<br />
     return true;<br />
   }<br />
<br />
   public static function count($timestamp = 0, $hasAnonymous = true)<br />
   {<br />
     global $db;<br />
     if (!$hasAnonymous) {<br />
       $cond = ' AND uid &gt; 0';<br />
     } else {<br />
       $cond = '';<br />
     }<br />
     $result = $db-&gt;query('SELECT COUNT(0) FROM sessions WHERE timestamp <br />
 &gt; ' . $timestamp . $cond);<br />
     return $result-&gt;one();<br />
   }<br />
}<br />
<br />
<br />
<br />
<br />
<br />
-- <br />
PHP General Mailing List (http://www.php.net/)<br />
To unsubscribe, visit: <a href="http://www.php.net/unsub.php" target="_blank"  rel="nofollow">http://www.php.net/unsub.php</a>]]></description>
            <dc:creator>Mingda</dc:creator>
            <category>php-general</category>
            <pubDate>Mon, 16 Apr 2012 04:10:01 +0200</pubDate>
        </item>
    </channel>
</rss>
