16, October 2008

[Modification] Reduce overhead by displaying static avatars - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web site promotion  >  Promoting & building a forum  >  SMF moding & promoting
Topic: [Modification] Reduce overhead by displaying static avatars
« previous next »
Pages: [1] Print

Author Topic: [Modification] Reduce overhead by displaying static avatars  (Read 894 times)
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8132
41749 credits
Members referred : 3



« on: Oct 27, 2006, 07:51:21 PM »

Recently I discovered that when a user uploads a custom image for avatar, the SMF see this image as an attachment.

So any time that the avatar is loaded a secondary php process will be opened, load all the non usefull things - users, functions, actions, etc - , will execute some queries, just to display an avatar!

The modification bellow will override the attachment thing, so it will simply display the image path, which is many times faster.

The only requirement for this to work is to hold your attachment directory in a visible from the web directory - actually a sub directory of the board index - which in most SMF installations is that way (even if it is not the script will tell you Smiley ).

So here we are. Just create a php file with the above code, and upload it to your forum's root directory. Execute it and everything will be fine.

Code:
<?php
//Author : Nick Papanotas
//Website : http://www.webdigity.com/
//Optimize SMF by using static avatars

set_time_limit(100);
include 
'./Settings.php';

$db_con = @mysql_connect($db_server$db_user$db_passwd) or die('Cant connect to DB');

$res mysql_db_query($db_name,"SELECT value FROM {$db_prefix}settings WHERE variable = 'attachmentUploadDir' LIMIT 1"$db_con);
$attachDir array_pop(mysql_fetch_array($res));
//Is it public?
if ( substr($attachDir0strlen($boarddir)) == $boarddir )
{
  
$url $boardurl substr($attachDirstrlen($boarddir)) . '/';
$res mysql_db_query($db_name,"SELECT filename,ID_MEMBER FROM {$db_prefix}attachments WHERE ID_MEMBER > 0"$db_con);
$avatars = array();
while ( $rec mysql_fetch_array($res))
{
  $avatars[] = array(
   'fn' => $rec['filename'],
   'id' => $rec['ID_MEMBER']
  );
}
if ( count($avatars) == )die ('Nothing to do here....');
foreach ( $avatars as $rec )
{
  mysql_db_query($db_name,"UPDATE {$db_prefix}members 
  SET `avatar` = '"
.$url.$rec['fn']."' WHERE ID_MEMBER = ".$rec['id']." LIMIT 1"$db_con);
}
echo 'Done with '.count($avatars).' avatars';
} else die(
'Propably this is not a public directory. I quit');
?>


Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=4589
Tags : php simple machines forum Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] Print 
Webdigity Webmaster Forums  >  Web site promotion  >  Promoting & building a forum  >  SMF moding & promoting
Topic: [Modification] Reduce overhead by displaying static avatars
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Oct 16, 2008, 06:10:20 AM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!





Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2008 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.