 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
k3ph
Joined: 21 Jul 2006 Posts: 123
|
Posted: Fri Jun 20, 2008 7:51 pm Post subject: phpBB search bug |
|
|
it seems this forum needs a prune...
key search: list window _________________ [ profile | ahk.net | ahk.talk ] |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6772 Location: Pacific Northwest, US
|
Posted: Fri Jun 20, 2008 8:34 pm Post subject: |
|
|
I cannot recreate this issue. how did you do it? _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
k3ph
Joined: 21 Jul 2006 Posts: 123
|
Posted: Fri Jun 20, 2008 8:46 pm Post subject: |
|
|
no idea, ive searched this keyword: window list
then, ive searched again but backwards: list window _________________ [ profile | ahk.net | ahk.talk ] |
|
| Back to top |
|
 |
Oberon
Joined: 18 Feb 2008 Posts: 458
|
Posted: Fri Jun 20, 2008 8:52 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2397
|
Posted: Sun Jun 22, 2008 4:25 am Post subject: |
|
|
| 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... |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Sat Jun 28, 2008 12:40 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Sat Jun 28, 2008 1:33 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Mon Jun 30, 2008 10:06 pm Post subject: |
|
|
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); |
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|