php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #24252 Problem with session_set_save_handler() when connecting to db outside of obj
Submitted: 2003-06-18 23:57 UTC Modified: 2010-12-21 19:37 UTC
Votes:9
Avg. Score:4.8 ± 0.6
Reproduced:5 of 5 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: jpenn at cheetah-soft dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 4.3.1 OS: RHAT 7
Private report: No CVE-ID: None
 [2003-06-18 23:57 UTC] jpenn at cheetah-soft dot com
Description:
------------
When connecting to the database inside the class object, everything works fine with session_set_save_handler(). But, when connecting outside of the class that holds the methods, php does'nt recognize there is an active connection to the DB. Is this a known problem that I have overlooked in the bug db?

I have tried everything, including passing the res id of the connection into the session handler class but to no avail.

~ Thanks


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-19 00:31 UTC] derick@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PHP.

 [2003-06-26 18:23 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 [2003-06-27 03:02 UTC] jpenn at cheetah-soft dot com
Ok - I thought the first post was clear.

When using session_set_save_handler() inside a class when using a DB as the storage medium - you must connect to the DB inside of the open function/method. First, we set the methods to use:

session_set_save_handler( array( &$this, 'open' ), array( &$this, 'close' ), array( &$this, 'read' ), array( &$this, 'write' ), array( &$this, 'destroy' ), array( &$this, 'gc' ) );

Now, this is the open method:

function open( $blah, $blah )
{
      $res = mysql_connect( 'blah', 'blah', 'blah' );
      mysql_select_db( 'blah', $res );
      return( true );
}

The above works. When explicitly connecting inside of the open method - everything works like a charm.

Now, if you DO NOT EXPLICITLY CONNECT (to the DB) inside of this method - the session handler will not work. This is just not specific to one DB and (or) operating system, it is a problem accross a magnitude of platforms.

Is this a scope issue?
 [2003-07-07 19:42 UTC] sniper@php.net
Either I don't understand what you mean with this or you're just expecting some weird magic to happen there. (of course you have to connect to the database...)

Provide a FULL but short example script if you still think this is some bug.


 [2003-07-07 19:59 UTC] jpenn at cheetah-soft dot com
Sniper - the example is in my last post. Also:

[quote]
(of course you have to
connect to the database...)
[/quote]
Where did you come up with that? Who in there right mind would think you would not have to connect to the DB? The whole bug can be summed up with that small quote.

If you DO NOT CONNECT TO THE DB WITHIN THE OPEN METHOD - it will not work.

- It will not work if you connect outside of the class
- It will not work if you connect inside the class but in a method other than the sess_open method
- It will not work if you connect with a DB commection class

It will ONLY WORK if you connect inside the open method for that function - the session_set_save_handler() function.

Excuse me for getting fustrated - but this was almost a simple bug report, and very understandable from my first post. This is almost as simple to understand as anything else the langauge has to offer.

~ Thanks
 [2003-07-09 08:41 UTC] sniper@php.net
As long as you fail to provide a full, but short example script which CLEARLY shows whatta hell you're talking about, this stays bogus.

 [2003-07-09 10:40 UTC] jpenn at cheetah-soft dot com
[quote]
As long as you fail to provide a full, but short example script which
CLEARLY shows whatta hell you're talking about, this stays bogus.
[/quote]
What in gods name are you talking about? Do you not see in the 4th post on this bug? That is as clear as it gets. Are you a kid or something sniper? This is rediculous that you are popping in and out of this and totally overlooking the posts on this bug.

[From 4th post in this bug]
session_set_save_handler( array( &$this, 'open' ), array( &$this,
'close' ), array( &$this, 'read' ), array( &$this, 'write' ), array(
&$this, 'destroy' ), array( &$this, 'gc' ) );

Now, this is the open method:

function open( $blah, $blah )
{
      $res = mysql_connect( 'blah', 'blah', 'blah' );
      mysql_select_db( 'blah', $res );
      return( true );
}
--------------------------------------------

Do you not see that? Do you want it emailed to you?
 [2003-07-09 10:51 UTC] jpenn at cheetah-soft dot com
What do you want sniper. Do you want the whole 300 lines of code from the session handler?
 [2003-07-09 10:55 UTC] sniper@php.net
Please leave the personal insults out.
You still don't seem to understand what "full but short" script means so I'll try and explain it simply:

1. It starts with <?php and ends with ?>
2. I can copy'n'paste it from this report to a file and run
without having to edit it / add to it
3. It contains ONLY the necessary lines which show the problem

Clear now?

 [2003-07-09 11:09 UTC] jpenn at cheetah-soft dot com
sniper - sorry for the personal insults, no harm meant. Problem is, what you just explained as 'full but short' - that is exactly what was posted - without the opening and closing php tags.

Problem is you can't cut and paste this code as it will not work. If you are testing this you will need the entire class to do the testing as without all six (6) of the arg's, the session_set_save_handler() will not work at all. So, to get what this bug is, you will need the class itself, which can be found at this address: http://www.cheetah-soft.com/csh/

Download the class and set up something temporary for it. Once you have the class as downloaded, it will run fine.

After you have it running, move the db connection outside of the class and you will see the bug.

Thanks
 [2003-09-14 23:14 UTC] jpenn at cheetah-soft dot com
Anyone know what the actuall status of this is. I see that the category was changed to 'feature request', not really sure why.

Is this an internal problem with ZE1?

~ Thanks
 [2010-12-21 19:37 UTC] johannes@php.net
-Status: Open +Status: Bogus -Package: Feature/Change Request +Package: *General Issues
 [2010-12-21 19:37 UTC] johannes@php.net
This can't be done in another way. There are multiple factors affecting this. For instance session.auto-start might start a session before the actual script runs. Then there's the whole shutdown order chicken and egg problem: what should be shutdown first - global variables or sessions? - If sessions first: What happens to destructors trying to access sessions. if variables first - well, you see it, the session can't access the connection.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jun 18 11:01:31 2024 UTC