>"Richard Lynch" <[EMAIL PROTECTED]> wrote:
> > The writing of the session data occurs *after* the server-browser HTTP
> > connection is cut.
>
> > If you have any error-reporting happening in your session_write 
>function,
> > you won't see it.
>
> > Alter that function to log errors to a file or something.
>
>It seems the pgsql_session_write() function is not even being invoked.
>Here it is:
>
>+-----------------------------------------------------------------
>| function pgsql_session_write($key, $val)
>| {
>|      /* debugging */
>|      $fp = fopen("/tmp/phpdebugwrite","w") or die ("can't open file");
>|     fwrite($fp, "HERE");
>|     fclose($fp);
>|      /* end debug */

Why don't you just use error_log() function and write errors to a file?

>|
>|     global $pgsql_session_handle, $pgsql_session_table;
>|
>|     $key = addslashes($key);
>|     $val = addslashes($val);
>|     $now = time();
>|
>|
>|
>|     /*
>|      * Delete any existing data for this session and then insert a new 
>row
>|      * containing the current session data, all in a single transaction.
>|      * This should prevent collisions between multiple session instances.
>|      *
>|      * Thanks to "Will Fitzgerald" <[EMAIL PROTECTED]>.
>|      */
>|     $query = 'begin; ';
>|     $query .= "delete from $pgsql_session_table where session_id = 
>'$key'; ";
>|     $query .= "insert into $pgsql_session_table values('$key', $now, 
>'$val'); ";
>|     $query .= 'commit;';
>|     $result = @pg_exec($pgsql_session_handle, $query);

I've seen this kind of implmentatin

delete ....
insert ....

IMHO, 2 sql operation that requires locks for session handling is just a 
waste
of resources. (delete requires higher lock level than select, transaction 
needs more resources, for each delete, insert requires fsync() and requires 
more disk head movements, etc, etc)
Unless you would like to implement some kind of session key validation to 
session handlers, simple

select ....
insert or update ...

may give better performance with many web servers and users. (may not make 
any significant improvement, though. Disabling PostgreSQL's fsync() for 
session db would much better result. Just FYI)

>|
>|     $ret = (pg_cmdtuples($result) == 0);
>|     pg_freeresult($result);
>|
>|     return ($ret);
>| }
>+-----------------------------------------------------------------
>
>I've added the debugging statements at the top.  Can you see anything
>wrong with this function?  At the end of the include file in which
>this appears, is the session_set_save_handler() call:

You will not get output from die('.....') ( or any print/echo) in session
handlers. Just use error_log() or implement user defined error handler
so that you can trigger error to display session handler errors.

my example pg_session_write() looks like:

function pg_session_write ($session_id, $session_data) {
        global $db_session, $HTTP_SERVER_VARS, $HTTP_COOKIE_VARS;
        if (!$db_session) {
                error_log("session_write(): Cannot connect to database.",0);
        }
        if (strlen($session_data) > intval(SESS_DATA_MAX)) {
                error_log('Session data too large. Unable to update session data for 
session '. $session_id, 0);
        }

        if (strlen($session_id) != 32) {
                error_log("session_write(): Invalid Session ID",0);
                return 0;
        }
        $session_id = addslashes($session_id);
        $session_data = addslashes($session_data);
        $uid = isset($HTTP_COOKIE_VARS['t_uid']) ? 
addslashes($HTTP_COOKIE_VARS['t_uid']) : '';

        $query = 'SELECT session_id, i_session_counter FROM '. SESS_TABLE ." WHERE 
session_id = '$session_id'";
        $result_id = pg_exec($db_session,$query);
        $session_exist = pg_numrows($result_id);

        if ($session_exist == 0) {
//              $query = 'INSERT INTO '. SESS_TABLE ." (session_id, i_time_created, 
i_last_active, t_remote_addr, t_session_data) VALUES ('$session_id', ". 
time() .", ". time() .", '". 
isset($HTTP_ENV_VARS['HTTP_X_FORWARDED_FOR'])?$HTTP_ENV_VARS['HTTP_X_FORWARDED_FOR']:$HTTP_SERVER_VARS['REMOTE_ADDR']
 
."', '$session_data')";
                $query = 'INSERT INTO '. SESS_TABLE ." (session_id, i_time_created, 
i_last_active, t_uid, t_remote_addr, t_session_data) VALUES ('$session_id', 
". time() .", ". time() .", '$uid', '". $HTTP_SERVER_VARS['REMOTE_ADDR'] 
."', '$session_data')";
        }
        else {
                $rec = pg_fetch_array($result_id,0,PGSQL_ASSOC);
                $query = 'UPDATE '. SESS_TABLE ." SET t_session_data = 
'$session_data', 
i_last_active = ". time() .", t_uid = '$uid' , i_session_counter = ". 
intval(++$rec['i_session_counter']) ." WHERE session_id = '$session_id'";
        }
        $rows_affected = pg_cmdtuples(pg_exec($db_session,$query));
//error_log($query, 0);
        if (!$rows_affected) {
                error_log('session_write(): Failed to INSERT or UPDATE session.',0);
        }
        return $rows_affected;
}


>
>session_set_save_handler(
>     'pgsql_session_open',
>     'pgsql_session_close',
>     'pgsql_session_read',
>     'pgsql_session_write',
>     'pgsql_session_destroy',
>     'pgsql_session_gc'
>);
>
>
>Thanks,
>--
>Steve <[EMAIL PROTECTED]>
>"And when you walk in golden halls, you get to keep the gold that falls"
>     -- Black Sabbath, "Heaven and Hell"
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>To contact the list administrators, e-mail: [EMAIL PROTECTED]
>

_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to