AutoHotkey Community

It is currently May 26th, 2012, 8:30 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: phpBB search bug
PostPosted: June 20th, 2008, 7:51 pm 
Offline

Joined: July 21st, 2006, 12:26 am
Posts: 223
Image
it seems this forum needs a prune...
key search: list window

_________________
                                  [ profile | ahk.net | ahk.talk ]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 20th, 2008, 8:34 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8666
Location: Salem, MA
I cannot recreate this issue. how did you do it?

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 20th, 2008, 8:46 pm 
Offline

Joined: July 21st, 2006, 12:26 am
Posts: 223
no idea, ive searched this keyword: window list
then, ive searched again but backwards: list window

_________________
                                  [ profile | ahk.net | ahk.talk ]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 20th, 2008, 8:52 pm 
Offline

Joined: February 18th, 2008, 8:26 pm
Posts: 442
I've also seen this error on a few rare occasions which is one of the reasons why I use google to search autohotkey.com. Upgrading to phpbb3 or using InnoDB over ISAM engine should solve the problem, but I don't see either happening for a long time.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 22nd, 2008, 4:25 am 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2542
I have seen similar errors before but always thought that they were due to server issues since later I have not been able to reproduce them...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 28th, 2008, 12:40 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
I did a "check table search_results" and the table was ok. I also did "truncate table search_results" in case there was any old data in it.

Please let me know if it happens again. Perhaps it is some kind of split-second timing issue where two people searching at the same time are assigned the same search_id.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 28th, 2008, 1:33 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
I researched this more, and made the following change to phpBB's search.php to try to prevent if from happening again.
Code:
// Commented out the following line because PHP.net says: "As of PHP 4.2.0, there is no need to seed the random number generator with srand() or mt_srand() as this is now done automatically."
//mt_srand ((double) microtime() * 1000000);
$search_id = mt_rand();
So now the odds of two simultaneously-executing searches being assigned the same ID seem very close to zero.

It's interesting to note that there is already code in search.php to ensure that the search_id isn't a duplicate. But it can happen anyway when two instances of search.php are running simultaneously and both reach the duplicate-check at around the same time. Then it becomes a race to see which instance can insert the shared search_id first.

Thanks for reporting it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 30th, 2008, 10:06 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
The above wasn't enough to fix this issue; so for anyone who needs it for their phpBB2 forum, here's a new fix that seems to work:

IN SEARCH.PHP, REPLACE THE FOLLOWING:
Code:
$search_id = mt_rand();

$sql = "UPDATE " . SEARCH_TABLE . "
   SET search_id = $search_id, search_time = $current_time, search_array = '" . str_replace("\'", "''", $result_array) . "'
   WHERE session_id = '" . $userdata['session_id'] . "'";
if ( !($result = $db->sql_query($sql)) || !$db->sql_affectedrows() )
{
   $sql = "INSERT INTO " . SEARCH_TABLE . " (search_id, session_id, search_time, search_array)
      VALUES($search_id, '" . $userdata['session_id'] . "', $current_time, '" . str_replace("\'", "''", $result_array) . "')";
   if ( !($result = $db->sql_query($sql)) )
   {
      message_die(GENERAL_ERROR, 'Could not insert search results', '', __LINE__, __FILE__, $sql);
   }
}
WITH THE FOLLOWING:
Code:
$max_search_id_retries = 20;
for ($i = 0; $i < $max_search_id_retries; $i++) // Retry on failure to insert.  Limit the number of retries to avoid infinite loop when failure is due to something other than "search_id already exists".
{
   $search_id = mt_rand();
   
   $sql = "UPDATE " . SEARCH_TABLE . "
      SET search_id = $search_id, search_time = $current_time, search_array = '" . str_replace("\'", "''", $result_array) . "'
      WHERE session_id = '" . $userdata['session_id'] . "'";
   if ( !($result = $db->sql_query($sql)) || !$db->sql_affectedrows() )
   {
      $sql = "INSERT INTO " . SEARCH_TABLE . " (search_id, session_id, search_time, search_array)
         VALUES($search_id, '" . $userdata['session_id'] . "', $current_time, '" . str_replace("\'", "''", $result_array) . "')";
      if ( !($result = $db->sql_query($sql)) )
         continue;  // Try again by generating a new search_id.
   }
   break;  // Since above didn't "continue", the update-or-insert succeeded.  No more retries needed.
}
if ($i >= $max_search_id_retries)
   message_die(GENERAL_ERROR, 'Could not insert search results', '', __LINE__, __FILE__, $sql);


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group