Jump to content

Speeding Up Loading Times


Recommended Posts

Posted

Very informative post indeed and thanks @CycleChat, I'm currently on shared hosting (working on a new site) and I used the Flush code and also optimize.php script that @Dan shared, very nice. Thanks to you all

  • Replies 53
  • Created
  • Last Reply
Posted

No it shouldn't be visible but if you type what CycleChat suggested it would be. The "flush" code never ran.. and if it did, you would probably get errors. This is because when you flush the page the server has to issue response headers.. and any attempts to modify or add on to those headers after the flush call would produce an error message since they were already sent.





Thanks for clearing that up ... :)

Cheers,
Shaun :D
Posted

I'd agree with just about everything CycleChat has said. Just a couple of thoughts:



1. I'm not sure about using FastCGI over PHP as a DSO, I don't feel it is as beneficial as it sounds. I personally (and we at IPS) run PHP as a DSO and it works well.



2. If you're running PHP as a DSO, use the APC extension, it makes a big difference.



3. This script can help you find and optimize tables that need it:



<?php


$autoAnswerLarge = null;

if(array_key_exists(1, $argv))

{

	$autoAnswerLarge = ($argv[1] == 'y' || $argv[1] == '-y') ? 'y' : 'n';

}


$host     = 'localhost';

$username = null;

$password = null;

$limitdb  = false;


if(is_file('/etc/mysql/debian.cnf'))

{

	//----

	// Ubuntu:

	//----


	// Open file:

	$conf = file_get_contents('/etc/mysql/debian.cnf');


	// Get username:

	$matches  = array();

	preg_match('/users+=s+([^n]+)/', $conf, $matches);

	$username = trim($matches[1]);


	// Get password:

	$matches  = array();

	preg_match('/passwords+=s+([^n]+)/', $conf, $matches);

	$password = trim($matches[1]);

}

elseif(is_file('/root/.my.cnf'))

{

	//----

	// cPanel:

	//----


	// Open file:

	$conf = file_get_contents('/root/.my.cnf');


	// Get username:

	$matches  = array();

	preg_match('/user=(")?([^"n]+)(")?/', $conf, $matches);

	$username = trim($matches[2]);

	$username = str_replace('"', '', $username);


	// Get password:

	$matches  = array();

	preg_match('/pass=(")?([^n]+)/', $conf, $matches);


	$password = trim($matches[2]);


	if(substr($password, -1) == '"')

	{

		$password = substr($password, 0, -1);

	}

}

elseif(is_file('./conf_global.php'))

{

	//----

	// IP.Board:

	//----


	require_once('./conf_global.php');


	$host     = $INFO['sql_host'];

	$limitdb  = $INFO['sql_database'];

	$username = $INFO['sql_user'];

	$password = $INFO['sql_pass'];

}


if(!$username || !$password)

{

	die('Could not retrieve your MySQL access details.'.PHP_EOL);

}


$db = @new mysqli($host, $username, $password);


if($db->connect_error)

{

	die('Could not connect to MySQL: ' . $db->connect_error . PHP_EOL);

}


$res = $db->query('SELECT TABLE_SCHEMA, TABLE_NAME, DATA_LENGTH FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema', 'mysql', 'eximstats') AND Data_free > 0');


if(!$res->num_rows && !$db->error)

{

	print 'No tables to optimize! :-)' . PHP_EOL;

}

elseif($db->error)

{

	print $db->error . ' :-( ' . PHP_EOL;

}


while($row = $res->fetch_assoc())

{

	if($limitdb !== false && $row['TABLE_SCHEMA'] != $limitdb)

	{

		continue;

	}


	$response = 'n';

	if($row['DATA_LENGTH'] >= 10485760 && is_null($autoAnswerLarge))

	{

		// If the table has more than 10mb of data in it, ask first. Otherwise just do it.

		print PHP_EOL . 'Optimize table: '. $row['TABLE_SCHEMA'] . '.' . $row['TABLE_NAME'] . '? (y/n) ';

		$response = trim(strtolower(fgets(STDIN)));

	}

	elseif($row['DATA_LENGTH'] < 10485760 || $autoAnswerLarge == 'y')

	{

		print PHP_EOL . 'Optimizing table: ' . $row['TABLE_SCHEMA'] . '.' . $row['TABLE_NAME'] . PHP_EOL;

		$response = 'y';

	}



	if($response == 'y' || $response == 'yes')

	{

		$result = $db->query('OPTIMIZE TABLE ' . $row['TABLE_SCHEMA'] . '.' . $row['TABLE_NAME'])->fetch_assoc();


		if(strtolower($result['Msg_text']) == 'ok')

		{

			print '--- Done!' . PHP_EOL;

		}

		else

		{

			print '!!! Warning !!! Response from MySQL was: ' . $result['Msg_text'] . PHP_EOL;

		}

	}

	else

	{

		print '--- Skipped.' . PHP_EOL;

	}

}


print PHP_EOL;


exit(0);

This will work on cPanel servers, Debian / Ubuntu servers, or any server with IP.Board on, but you'll need SSH access to run it. Put that in a file called optimize.php - If you have root access, save it anywhere, otherwise put it in your IP.Board root folder. When you run it, it'll come up with output like so:

[root@monkey forum]# php optimizer.php 


Optimize table: test_ipb.ipb_core_item_markers_storage? (y/n) y

--- Done!


Optimize table: test_ipb.ipb_core_sys_conf_settings? (y/n) y

--- Done!


Optimize table: test_ipb.ipb_core_sys_cp_sessions? (y/n) y

--- Done!


Optimize table: test_ipb.ipb_core_sys_login? (y/n) y

--- Done!


Optimize table: test_ipb.ipb_forum_tracker? (y/n) y

--- Done!


Optimize table: test_ipb.ipb_forums? (y/n) y

--- Done!



Obviously if you have a huge forum, you'll want to be careful about saying yes to tables like topics, posts, etc. unless you're running it at a time that is appropriate for your site to be sluggish.








when I run this script from within Putty, nothing happens. What am I doing wrong? I've CD to the directory the file is in, and then use the command php optimize.php. Putty just drops down a line and then thats it.

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...