- 注册时间
- 2004-6-25
- 最后登录
- 1970-1-1
- 日志
- 阅读权限
- 50
|

楼主 |
发表于 2004-12-27 10:32:24
|
显示全部楼层
Automatic sessions table emptying script
Open includes/sessions.php using a text/code editor such as Wordpad, and find the following code (line 152).
- message_die(CRITICAL_ERROR, 'Error creating new session', '', __LINE__, __FILE__, $sql);
复制代码
Replace this with the following code.
- $error = TRUE;
- if (SQL_LAYER == "mysql" || SQL_LAYER == "mysql4")
- {
- $sql_error = $db->sql_error($result);
- if ($sql_error["code"] == 1114)
- {
- $result = $db->sql_query('SHOW TABLE STATUS LIKE "'.SESSIONS_TABLE.'"');
- $row = $db->sql_fetchrow($result);
- if ($row["Type"] == "HEAP")
- {
- if ($row["Rows"] > 2500)
- {
- $delete_order = (SQL_LAYER=="mysql4") ? " ORDER BY session_time ASC" : "";
- $db->sql_query("DELETE QUICK FROM ".SESSIONS_TABLE."$delete_order LIMIT 50");
- }
- else
- {
- $db->sql_query("ALTER TABLE ".SESSIONS_TABLE." MAX_ROWS=".($row["Rows"]+50));
- }
- if ($db->sql_query($sql))
- {
- $error = FALSE;
- }
- }
- }
- }
- if ($error)
- {
- message_die(CRITICAL_ERROR, "Error creating new session", "", __LINE__, __FILE__, $sql);
- }
复制代码
This script will delete the oldest 50 rows (no longer valid sessions) from the sessions table if there are more than 2500 rows in the table currently. If there are less than 2500 rows in the table, then 50 is added to the table's MAX_ROWS (see Why the table is full for more on MAX_ROWS). This basically means that the table's capacity gets bigger and bigger until the maximum amount of rows hits 2500. From then on, instead of increasing the table's capacity, the script deletes the oldest 50 (and no longer needed) sessions. |
|