Architecture / Installation

Architecture / Installation

duplicate key in tiki_sessions - a "solution"

posts: 1

perhaps I'm the only one that encountered this problem so far. it was hard enough just to dig it and "discover" what was causing.
my boss emails me with an error he gets at our front page:

Warning: error: Duplicate entry '5663207e3d6e1adc2b7bbe63b672c365' for key 1 in query:
insert into `tiki_sessions`(`sessionId`,`timestamp`,`user`) values(?,?,?)
in /home/www/*********/lib/tikidblib.php on line 134

I was like "What the hell?" — after days of trying to recreate the bug (apparently it only happened in an IPv6 env) I find myself reading the damn email again and see this:

array(3) {
      &string(73) "insert into `tiki_sessions`(`sessionId`,`timestamp`,`user`) values(?,?,?)"
      &array(3) {
----> HERE <-----      string(40) "5663207e3d6e1adc2b7bbe63b672c36583f32c3f"

And I see that the string for the SESSID is differente from above. After looking at the tiki_sessions structure, I realize it's a VARCHAR(32)...

I checked too that update_session() from tiki first tries to delete the key and then reinsert.

So, after some tests this is what was actually happening:
arrow Boss access webpage — tiki tries to insert a 40 chars long string and mysql truncates it to 32 chars but inserts
arrow Boss reloads webpage — tiki tries to delete a 40 chars long string from table (it doesn't exist and don't generate an error!!!!!)
arrow tiki tries to insert the 40 chars long string but mysql truncates it to 32 chars long and whines about already existing one key — NOW there's an error.

My solution: I changed my tiki_sessions table so sessionId is a VARCHAR(40) instead of 32.

I think this is probably a PHP bug but I haven't checked it yet.
I just want to know if this solution will affect any other thing (I personally think it won't).

I hope I explained my problem and "solution" fairly well :-)

php version: 4.3.10
tiki: 1.8.6
apache: 2.0.54

posts: 2881 United Kingdom

Nope its a IPV6 requirement, Just we mere mortals are still on old stuff ;)

You did well.


posts: 1092

Good job Nitio

Seems we will also encouter perhaps this problem with php5
From php.net
The way PHP5 creates session ids has changed. No longer are session ids always 32 characters. Rather it depends on how session.hash_function and and session.hash_bits_per_character
more fun....

posts: 43 United States


This info was very helpful for resolving an error that we experienced related to Scoring and unnecessarily long usernames. The affected users had usernames consisting of their full email addresses - first_last@mail.domain.com. When they tried to read certain blogs, they received a "duplicate key" error related to the event_id variable in the tiki_users_score table for entries like UserName-blog_is_read_User_Name@mail.domain.com:2, that had around 60 characters in some cases.

Solution: Drop the "@mail.domain.com" from the usernames. biggrin (Who the hell wants to type all that in each time anyway?)


Upcoming Events

1)  15 Jun 2023 14:00 GMT-0000
Tiki Roundtable Meeting - June 2023
2)  20 Jul 2023 14:00 GMT-0000
Tiki Roundtable Meeting - July