SMF Support > Server Performance and Configuration

Big Performance Tip: Specify a Custom Avatar Directory

(1/25) > >>

Mark Rose:
I just killed about 75% of my php hits by doing this.

Why? If you don't have a specified directory, SMF treats all avatars as attachments, and that means for every avatar displayed, the browser hits index.php to download the image (or at least check if has changed). The following command instructions assume you're in the base directory of the forum software.

First off, create a new directory that's publicly accessible. I chose "avs" as "avatars" was already taken (for the avatars included with SMF). You'll want to make sure it has the same permissions as the attachments directory (enough permission that the user the webserver and/or php run as can modify the contents).

Second, go to the Admin section, and under Avatar Settings, specify the Upload Directory and URL. You can use the settings under Server-stored avatars as a guide (just change avatars to avs).

Now all newly uploaded avatars will use the new directory. But what about all the old uploaded avatars that are still causing hits to php? We can take care of that by running a hidden URL in SMF. The hidden URL is different for SMF 1.1 and SMF 2.0.

* SMF 2.0: index.php?action=admin;area=manageattachments;sa=moveAvatars
* SMF 1.1: index.php?action=manageattachments;sa=moveAvatar
Now each request for an avatar will go directly to the image file, bypassing php. This will allow a user to use the avatar image on other sites (by copying the image URL), but it's a small price to pay for massively reduced php hits.

Done!


Alternatively, you can move the avatars manually:

First, copy the avatars from the attachments directory to the avs directory. Conveniently, all the attachment avatars follow the pattern "avatar_*" so a simple "cp -p attachments/avatars_* avs" should suffice.

Second, run this SQL query to inform SMF that users' avatars are in the new directory (we copied them above). Please note that if you used a different prefix for your tables than "smf_" you'll need to adjust the query.

--- Code: ---UPDATE `smf_attachments` SET `attachmentType` = '1' WHERE `smf_attachments`.`ID_MEMBER` != 0
--- End code ---

Lastly, it's time to clean up the old avatars. Running "rm attachments/avatar_*" should take care of that.

Ben_S:
There is an easier way to do this using a built in hidden feature, I posted similar a while back in a hidden board so will just post it all here again.

If you allow users to upload their own avatars, move them to a specific directory rather than have them handled through the attachments system. This way you will save a big chunk of resources since they are served in a "normal way" rather than through index.php

You can do this through Admin > Attachments and Avatars > Avatar Settings > Upload avatars to > Specific directory.

Naturally create the directory and make it writable.

To move existing avatars to the new directory, access index.php?action=manageattachments;sa=moveAvatars

Be warned though your page views stats will drop to the floor, for some reason webalizer and awstats wrongly think an avatar loaded on a page is a page itself rather than a hit.

Mark Rose:

--- Quote from: Ben_S on October 01, 2007, 04:43:37 AM ---There is an easier way to do this using a built in hidden feature, I posted similar a while back in a hidden board so will just post it all here again.

If you allow users to upload their own avatars, move them to a specific directory rather than have them handled through the attachments system. This way you will save a big chunk of resources since they are served in a "normal way" rather than through index.php

You can do this through Admin > Attachments and Avatars > Avatar Settings > Upload avatars to > Specific directory.

Naturally create the directory and make it writable.

To move existing avatars to the new directory, access index.php?action=manageattachments;sa=moveAvatars

Be warned though your page views stats will drop to the floor, for some reason webalizer and awstats wrongly think an avatar loaded on a page is a page itself rather than a hit.


--- End quote ---

Guess I should have spent more time reading the source! lol

Will this change also affect Alexa rankings?

Ben_S:
Not got the foggiest to be honest, have never batted an eyelid at Alexa as it's pointless IMO, it shouldn't do though since the toolbar should accurately work out what is a page and what isn't

Mark Rose:

--- Quote from: dannbass on October 04, 2007, 04:18:37 PM ---I'm not able to move the old avatars... ::) with the hidden function.  Any other ways to do it?

--- End quote ---

Do it like I suggested in the first post :)

Navigation

[0] Message Index

[#] Next page

Go to full version