| ||||||||||
![]() |
Shopping cart software Solutions for online shops and malls | |||||||||
![]() |
![]() |
|
X-Cart Home | ![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Database Auto-Optimizer | ||||
![]() |
|
|
Thread Tools | Search this Thread |
#1
|
|||||||
|
|||||||
![]() This is a module to automatically optimize all of the tables in your database overnight through the use of a cronjob. Also performs repairs as needed.
First create a file in your Xcart root directory named: db_optimizer.php Put the following inside that file: Code:
Next create a cronjob that runs sometime each day whenever your site has the least amount of traffic. Use the cron command: php /absolute-path-to-this-file/db_optimizer.php Substitute the data in the constants section of this file with your specific information. Also replace absolute-path-to's with the appropriate path. That's all there is to it. If there are any problems, let me know! ![]()
__________________
X-Cart Pro 4.5.5 Platinum X-Payments 1.0.6 PHP 5.3.14 MySQL 5.1.68 Apache 2.2.23 |
|||||||
#2
|
|||||||
|
|||||||
![]() Hi NuAlpha
Thank you for sharing this file. I've been looking for something like this for sometime. I ran the script from my browser without any problems. Next I'll try to set up the cron file. Just need to learn a bit more about doing this. Once again, thank you
__________________
Mike X-Cart Gold Version 4.6.0 PHP 5.2.17 |
|||||||
#3
|
|||||||
|
|||||||
![]() Here is an update of the code. Noticed a potential security issue. This fix might disable the script on some people's servers so if it does and you have another solution, then just remove the condition. The condition if (empty($_SERVER['REMOTE_ADDR']) && empty($_SERVER['SERVER_ADDR'])) below is meant to prevent anyone but the cronjob from running the script.
I have also added the ability to optimize more than one database. This is useful if, for instance, you have your stie stats recorded to a seperate database. Code:
__________________
X-Cart Pro 4.5.5 Platinum X-Payments 1.0.6 PHP 5.3.14 MySQL 5.1.68 Apache 2.2.23 |
|||||||
#4
|
|||||||
|
|||||||
![]() Not being one that is all that familiar with mysql (thats what I pay others for), what happens to a database when it's being optimised?? i.e what does it actually do?
__________________
x-cart 4.0.5 (live and heavily modded) Server: freebsd |
|||||||
#5
|
|||||||
|
|||||||
![]() Quote:
From the MySQL manual... "Deleted records are maintained in a linked list and subsequent INSERT operations reuse old record positions. You can use OPTIMIZE TABLE to reclaim the unused space and to defragment the data file." Basically, optimizing the tables keeps record access as fast as possible. This module also detects and auto-repairs any damaged tables as well. ![]()
__________________
X-Cart Pro 4.5.5 Platinum X-Payments 1.0.6 PHP 5.3.14 MySQL 5.1.68 Apache 2.2.23 |
|||||||
#6
|
|||||||
|
|||||||
![]() I guess I just run a bash script via cron that optimizes my tables and then backs them up.
Code:
__________________
No longer using Xcart, was good while it lasted. |
|||||||
#7
|
|||||||
|
|||||||
![]() Quote:
Looks good. Some people can't access bash in that manner because of security restrictions set in place by the company which provides their servers. Would work fine for a dedicated server though.
__________________
X-Cart Pro 4.5.5 Platinum X-Payments 1.0.6 PHP 5.3.14 MySQL 5.1.68 Apache 2.2.23 |
|||||||
#8
|
|||||||
|
|||||||
![]() Great job NuAlpha
![]() And with regards to security mentioned further up in thread, if you can run cronjobs on your account then just put db_optimizer.php in a non web-accessible directory ie: one directory up from your public_html directory |
|||||||
#9
|
|||||||
|
|||||||
![]() Quote:
HAH!! Good idea! And here I was rewriting the code to solve a simple problem. For some reason clever code always seems like the best solution in my mind even though there is probably some simpler way of taking care of the issue at hand. ![]()
__________________
X-Cart Pro 4.5.5 Platinum X-Payments 1.0.6 PHP 5.3.14 MySQL 5.1.68 Apache 2.2.23 |
|||||||
#10
|
|||||||
|
|||||||
![]() When I run db_optimizer.php, I get the following mySQL error:
Code:
I've tried the variations of db_optimizer.php given here, but they both result in the same error. I would prefer to run the bash script rather than the php anyway, and I have access to bash, but I have no idea how set up and run bash scripts. Any help on getting either method to work is much appreciated. Thanks! =========== mySQL: 4.1.11 Apache/1.3.33 (Unix) PHP/4.3.11 mod_perl/1.29 xcart: 4.0.15 |
|||||||
|
|||
X-Cart forums © 2001-2020
|