optimizing tables with php

Started on the old forum in April 2010 · view the original in the archive · old links redirect here

2 replies · 1,036 views · started 16 years ago · 1 min read

3 participants
subzero Super moderator Fellow · 3,954 posts #1
<?php
$db = mysql_connect('localhost','user','password');
if(!$db) echo "cannot connect to the database";
mysql_select_db('user_drpl1');
$result=mysql_query('OPTIMIZE TABLE accesslog,cache,comments,node,users,watchdog;');
echo mysql_error();
?>

Change user, password and user_drpl1 to reflect your Drupal MySQL username, password and database.

This will optimize the tables accesslog, cache, comments, node, users and watchdog. Feel free to add or remove tables from the query.

Once you have inserted the code, save the file. For the purposes of this example, we'll assume that the file is called optimize.php. Once the file is saved in your folder, you can execute it directly from a browser:

404 - Not Found

If you get a blank page without any errors, this means that the tables have been successfully optimized 🙂

You can also set a cron job in order to execute the optimization script at regular intervals. The cron job you set should be similar to this:

php /home/user/public_html/YOURLOGIN/optimize.php

Make sure you don't set the cron to be executed too often. Once a week should be more than enough to keep your tables optimized 🙂

here is other way doing it

i like using this way

each page you place your sql commands like

like index.php you place

@mysql_query("OPTIMIZE TABLE online") or die(mysql_error());
@mysql_query("OPTIMIZE TABLE user") or die(mysql_error());
@mysql_query("OPTIMIZE TABLE forums") or die(mysql_error());
@mysql_query("OPTIMIZE TABLE status") or die(mysql_error());
@mysql_query("OPTIMIZE TABLE download") or die(mysql_error());
@mysql_query("OPTIMIZE TABLE settings") or die(mysql_error());

i like that way as each user past your site or has a look it optimize the table for you. better then adding cron job's

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

Mysterio Lead · 630 posts #2

thanks sub! i am in mobile now, with click "thanks" tomorrow!

mysterio.al - programming is a functional art

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close