PHP code example of simbiat / optimize-tables
1. Go to this page and download the library: Download simbiat/optimize-tables library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
simbiat / optimize-tables example snippets
(new \Simbiat\optimizeTables)->analyze('schema');
array (
'bic__bik_swif' =>
array (
'TABLE_NAME' => 'bic__bik_swif',
'ENGINE' => 'InnoDB',
'ROW_FORMAT' => 'Compressed',
'TABLE_ROWS' => '387',
'DATA_LENGTH' => '24576',
'INDEX_LENGTH' => '8192',
'DATA_FREE' => '0',
'TOTAL_LENGTH' => '32768',
'FRAGMENTATION' => '0.0000',
'FULLTEXT' => '0',
'TO_COMPRESS' => false,
'TO_ANALYZE' => true,
'TO_CHECK' => true,
'TO_HISTOGRAM' => true,
'TO_OPTIMIZE' => false,
'TO_REPAIR' => false,
'COMMANDS' =>
array (
0 => 'SET @@SESSION.old_alter_table=false;',
1 => 'SET @@SESSION.alter_algorithm=\'INPLACE\';',
2 => 'SET @@GLOBAL.innodb_defragment=true;',
3 => 'CHECK TABLE `simbiatr_simbiat`.`bic__bik_swif` FOR UPGRADE EXTENDED;',
4 => 'ANALYZE TABLE `simbiatr_simbiat`.`bic__bik_swif`;',
5 => 'ANALYZE TABLE `simbiatr_simbiat`.`bic__bik_swif` PERSISTENT FOR ALL;',
6 => 'SET @@SESSION.old_alter_table=DEFAULT;',
7 => 'SET @@SESSION.alter_algorithm=DEFAULT;',
8 => 'SET @@GLOBAL.innodb_defragment=DEFAULT;',
9 => 'SET @@GLOBAL.innodb_optimize_fulltext_only=DEFAULT;',
),
),
)
(new \Simbiat\optimizeTables)->optimize('schema');
array (
1586091446410816 => 'Getting list of tables...',
1586091449185271 => 'Attempting to enable maintenance mode using \'UPDATE `simbiatr_simbiat`.`settings` SET value = true WHERE `settings`.`setting` = \'maintenance\';\'...',
1586091449185567 => 'Maintenance mode enabled.',
1586091449185579 => 'Updating settings for optimization...',
1586091449185584 => 'Attempting to update setting \'SET @@SESSION.old_alter_table=false;\'...',
1586091449185704 => 'Successfully updated setting.',
1586091449185716 => 'Attempting to update setting \'SET @@SESSION.alter_algorithm=\'INPLACE\';\'...',
1586091449185839 => 'Successfully updated setting.',
1586091449185850 => 'Attempting to update setting \'SET @@GLOBAL.innodb_defragment=true;\'...',
1586091449186018 => 'Successfully updated setting.',
1586091451043050 => 'Checking `bic__bik_swif`...',
1586091451043385 => 'Successfully checked `bic__bik_swif`.',
1586091451043407 => 'Analyzing `bic__bik_swif`...',
1586091451046106 => 'Successfully analyzed `bic__bik_swif`.',
1586091451046131 => 'Creating histograms for `bic__bik_swif`...',
1586091451060711 => 'Successfully created histograms for `bic__bik_swif`.',
1586091762231919 => 'Reverting settings after optimization...',
1586091762231934 => 'Attempting to update setting \'SET @@SESSION.old_alter_table=DEFAULT;\'...',
1586091762232198 => 'Successfully updated setting.',
1586091762232225 => 'Attempting to update setting \'SET @@SESSION.alter_algorithm=DEFAULT;\'...',
1586091762232435 => 'Successfully updated setting.',
1586091762232462 => 'Attempting to update setting \'SET @@GLOBAL.innodb_defragment=DEFAULT;\'...',
1586091762232675 => 'Successfully updated setting.',
1586091762232702 => 'Attempting to update setting \'SET @@GLOBAL.innodb_optimize_fulltext_only=DEFAULT;\'...',
1586091762232911 => 'Successfully updated setting.',
1586091762232956 => 'Attempting to disable maintenance mode using \'UPDATE `simbiatr_simbiat`.`settings` SET value = true WHERE `settings`.`setting` = \'maintenance\';\'...',
1586091762237817 => 'Maintenance mode disabled.',
)
{
"logs": {
"1586090907695229": "Getting list of tables...",
"1586090910393167": "No tables to process were returned. Skipping..."
},
"before": {
"bic__bik_swif": {
"TABLE_NAME": "bic__bik_swif",
"ENGINE": "InnoDB",
"ROW_FORMAT": "Compressed",
"TABLE_ROWS": "387",
"DATA_LENGTH": "24576",
"INDEX_LENGTH": "8192",
"DATA_FREE": "0",
"TOTAL_LENGTH": "32768",
"FRAGMENTATION": "0.0000",
"FULLTEXT": "0",
"TO_COMPRESS": false,
"TO_ANALYZE": true,
"TO_CHECK": true,
"TO_HISTOGRAM": true,
"TO_OPTIMIZE": false,
"TO_REPAIR": false,
"CHECK_DATE": 1586078961,
"CHECK_TIME": 224,
"ANALYZE_DATE": 1586078961,
"ANALYZE_TIME": 2087,
"HISTOGRAM_DATE": 1586078961,
"HISTOGRAM_TIME": 13604
}
},
"after": {
"bic__bik_swif": {
"TABLE_NAME": "bic__bik_swif",
"ENGINE": "InnoDB",
"ROW_FORMAT": "Compressed",
"TABLE_ROWS": "387",
"DATA_LENGTH": "24576",
"INDEX_LENGTH": "8192",
"DATA_FREE": "0",
"TOTAL_LENGTH": "32768",
"FRAGMENTATION": "0.0000",
"FULLTEXT": "0",
"TO_COMPRESS": false,
"TO_ANALYZE": true,
"TO_CHECK": true,
"TO_HISTOGRAM": true,
"TO_OPTIMIZE": false,
"TO_REPAIR": false,
"CHECK_DATE": 1586078961,
"ANALYZE_DATE": 1586078961,
"HISTOGRAM_DATE": 1586078961
}
}
}
(new \Simbiat\optimizeTables)->showStats();
(new \Simbiat\optimizeTables)->optimize('schema', true);
(new \Simbiat\optimizeTables)->optimize('schema', true, true);