forked from Plecebo/newznab-tmux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
optimize_myisam.php
56 lines (47 loc) · 1.84 KB
/
optimize_myisam.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
require(dirname(__FILE__)."/config.php");
require(WWW_DIR . '/lib/framework/cache.php');
require_once(WWW_DIR . '/lib/framework/db.php');
function quantity($force = false)
{
$db = new DB;
$ret = array();
if ($force)
$alltables = $db->query("show table status where `Engine` = 'MyISAM' and Data_free > 30000000");
else
$alltables = $db->query("show table status where `Engine` = 'MyISAM' and Data_free != 0 and Data_free < 30000001");
foreach ($alltables as $tablename)
{
$ret[] = $tablename['Name'];
}
return $ret;
}
function moptimize($force = false)
{
$db = new DB;
$ret = array();
if ($force)
$alltables = $db->query("show table status where `Engine` = 'MyISAM' and Data_free > 30000000");
else
$alltables = $db->query("show table status where `Engine` = 'MyISAM' and Data_free != 0 and Data_free < 30000001");
foreach ($alltables as $tablename)
{
$ret[] = $tablename['Name'];
echo "Optmze : Optimizing " . $tablename['Name'] . " MyISAM table.\n";
$db->queryDirect("REPAIR TABLE `" . $tablename['Name'] . "`");
$db->queryDirect("OPTIMIZE TABLE `" . $tablename['Name'] . "`");
$db->queryDirect("ANALYZE TABLE `" . $tablename['Name'] . "`");
}
return $ret;
}
$force = ((isset($argv[1]) && ($argv[1] == "true")));
$db = new DB;
echo "\033[1;41;33mOptmze : OPTIMIZATION OF THE MYISAM MYSQL TABLES HAS STARTED, DO NOT STOP THIS SCRIPT!\033[1;0;33m\n\n";
$qret = quantity($force);
echo "Optmze : Going to start optimizing ".count($qret)." MyISAM tables (if you have MyISAM tables).\n";
$ret = moptimize($force);
echo "Optmze : Finished optimizing ".count($ret)." MyISAM tables.\n";
if (count($ret) > 0)
echo "Optmze : Optimization completed.\033[1;37m\n";
else
echo "Optmze : Nothing requires optimization.".(!$force ? " Try using force (optimize_myisam.php true)" : "")."\033[1;37m\n";