Re: [PHP-DB] independent session data for multiple browser windows

2008-02-27 Thread Charles Whitaker


On Feb 20, 2008, at 11:18 AM, Gary Wardell wrote:



They'll be accessing different account records in different windows.
I keep track of the current account id in the session data, as well
as a number of other account-specific items. Once I was made
aware of
the multiple-window requirement, and started looking more closely at
sessions, it seemed (from the PHP documentation) that I could
start a
new session, with a different name and id, and that would take care
of it.  In fact I CAN start sessions with independent names and ids,
but their DATA doesn't seem to be completely independent.



Assuming that they are interacting through forms on the pages in  
the different windows, why not put the UID of the record they are

accessing in a hidden field in the form?


Gary,

Thanks for your reply. I'm beginning to think that that's what I'll  
have to do, although it will be a bit of work to convert. I'm  
surprised, though, that sessions aren't better in regards to data  
integrity. What I'm gathering from looking into this is that it's ok  
to use sessions, but you shouldn't count on reliable data from them.  
I don't remember seeing any caveats to that effect in the  
documentation on sessions, but that seems to be the case.


Anyone know differently? Thanks.

Charles Whitaker
Technical Staff
Open Door Networks



Re: [PHP-DB] independent session data for multiple browser windows

2008-02-20 Thread Charles Whitaker


On Feb 16, 2008, at 1:31 AM, Tobias Franzén wrote:


Charles Whitaker wrote:

Greetings,

I have a nearly-completed accounts/billing database using PHP and  
MySQL, and was just informed that users will want to access the  
database via multiple windows in one browser on the same machine,  
so I'm looking for a way to have each browser window have its own  
set of session data.


As far as I know, the only way for this to work reliably is if your  
users can manually choose to open a new "session" in a new window/ 
tab. Is this the way you want it to work? Because you can't  
reliably stop them from having the same session in multiple windows  
if they would so choose.


Tobias,

Thanks for the reply. With one window in Safari open, and accessing  
the database, they just want to create a new window ("New Window" in  
Safari's File menu) and access the database from that window as well.


On the other hand, why would you require multiple sessions if they  
are to work against the same database?

...
What kind of information stored in the session would require them  
to use different sessions for different tabs? If you give us a  
hint, we might be better able to help.


They'll be accessing different account records in different windows.  
I keep track of the current account id in the session data, as well  
as a number of other account-specific items. Once I was made aware of  
the multiple-window requirement, and started looking more closely at  
sessions, it seemed (from the PHP documentation) that I could start a  
new session, with a different name and id, and that would take care  
of it.  In fact I CAN start sessions with independent names and ids,  
but their DATA doesn't seem to be completely independent.


Charles Whitaker
Technical Staff
Open Door Networks



[PHP-DB] independent session data for multiple browser windows

2008-02-15 Thread Charles Whitaker

Greetings,

I have a nearly-completed accounts/billing database using PHP and  
MySQL, and was just informed that users will want to access the  
database via multiple windows in one browser on the same machine, so  
I'm looking for a way to have each browser window have its own set of  
session data.


I was initially using cookies, so I switched to propagating the  
session name via the URL, and had each window using a unique session  
name, but the DATA from each named session was written to the same  
file on disk (/private/var/tmp/whatever).


I noticed that the session data file name included the session id, so  
I tried propagating the session id in the URL, and setting the  
session id right before session_start() -- that resulted in two data  
files on disk, but one session would occasionally write to the other  
session's data file. At this point, this is the code I'm trying:


if (!array_key_exists('SESSION_ID', $_REQUEST)) {
$_REQUEST['SESSION_ID'] = 'SESS'.uniqid('');
}
session_name($_REQUEST['SESSION_ID']);
session_id($_REQUEST['SESSION_ID']);
session_start();
output_add_rewrite_var('SESSION_ID',$_REQUEST['SESSION_ID']);

In php.ini, I now have:
session.use_cookies = 0
session.use_only_cookies = 0
session.auto_start = 0

Also, I'm on Mac OS X Tiger, and everyone's using Safari. PHP  
5.0.24a, MySQL 4.1.22


Any suggestions on how to have unique session data for multiple  
windows in the same browser on the same machine? Seems like it must  
be doable, but I haven't figured it out yet. Thanks to whomever can  
help.


Charles Whitaker
Technical Staff
Open Door Networks



[PHP-DB] connection id mystery

2007-07-25 Thread Charles Whitaker

Greetings,

I'm developing a tech support log using php and MySQL. Users will 
add, delete and modify records. In fact, it's fully implemented 
except for concurrency control. I'm trying to use get_lock and 
release_lock to implement record-level locking, but when I go to 
release the lock, the connection id doesn't match the id used to get 
the lock, and so the release fails and the record stays, in effect, 
locked.


When a user loads the edit page for a record, get_lock is called with 
a unique id before the record is read. When the user saves changes, 
the edit page is reloaded, and the record is modified. The lock is 
released only after the user loads some other page.


It often works, but sometimes I see this in the log:
[25/Jul/2007:11:33:39] 192.168.2.102 InitSQL: new connection: pdo 
client id = 279		// load the edit page, and ...
[25/Jul/2007:11:33:39] 192.168.2.102 Lock iss_23 gotten using 
connection id 279		// lock the record.
[25/Jul/2007:11:33:42] 192.168.2.102 InitSQL: new connection: pdo 
client id = 288		// load some other page, but get a different 
connection id, and so ...
[25/Jul/2007:11:33:42] 192.168.2.102 Lock iss_23 was not gotten using 
current connection id (288), not released		// fail to 
unlock the record.


Since I'm requesting persistent connections, why don't I get the same 
connection each time? Or, to ask it another way: I notice that the 
number of threads slowly increases as I continue to access records -- 
why would this happen if I'm using persistent connections? I assumed 
that the first time I did 'new PDO' I'd create a connection, and each 
time after that I'd get the same connection. At least that's how I 
read the documentation.


Can anyone point me in the right direction? Thanks.

The gory details:

At the beginning of every page is a call to a function with this code:

$gSQL = new 
PDO('mysql:unix_socket=/tmp/mysql.sock;dbname=operations', 
$_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], 
array(PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => 
PDO::ERRMODE_EXCEPTION, PDO::ATTR_TIMEOUT => 86400));

// get connection id
$stmt = $sql->query('show processlist');
$therow = $stmt->fetch();
$pdoclientid = $therow['Id'];
elog('InitSQL: new connection: pdo client id = ' . $pdoclientid);

In the edit page I call to a function that does this:

// get the current connection id
$stmt = $gSQL->query('select connection_id()');
$therow = $stmt->fetch();
$connectionid = $therow[0];
// get the lock
$thelock = 'iss_' . $issueid;
foreach ($gSQL->query("select get_lock('" . $thelock . "', " . 1 . 
")") as $row) {

// check the result
$result = $row[0];
switch ($result) {
case 1:
		eLog("Lock " . $thelock . ' gotten using connection 
id ' . $connectionid);

return true;
break;
case 0:
eLog("Getting lock " . $thelock . ' timed out');
return false;
break;
case NULL:
eLog("Error getting lock " . $thelock);
return false;
break;
default:
return false;
break;
}
}

On all other pages, I try to release the lock with this code:

// get the current connection id
$stmt = $gSQL->query('select connection_id()');
$therow = $stmt->fetch();
$connectionid = $therow[0];
// try to release the lock
foreach ($gSQL->query("select release_lock('" . $thelock . "')") as $row) {
$result = $row[0];
switch ($result) {
case 1:
eLog("Lock " . $thelock . ' released');
break;
case 0:
			eLog("Lock " . $thelock . ' was not gotten 
using current connection id (' . $connectionid . '), not released');

break;
case NULL:
			eLog("Lock " . $thelock . ' does not exist, 
not released');

break;
default:
break;
}
}

--

Charles Whitaker

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php