Advertisement:

Author Topic: Big Performance Tip: Specify a Custom Avatar Directory  (Read 109569 times)

Offline Something like that

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 2,496
  • Gender: Male
  • ]
Big Performance Tip: Specify a Custom Avatar Directory
« on: September 30, 2007, 10:19:16 PM »
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: [Select]
UPDATE `smf_attachments` SET `attachmentType` = '1' WHERE `smf_attachments`.`ID_MEMBER` != 0
Lastly, it's time to clean up the old avatars. Running "rm attachments/avatar_*" should take care of that.
« Last Edit: January 11, 2010, 05:02:07 PM by «Mark» »

Offline Ben_S

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 11,702
  • xxx
Re: Big Performance Tip: Specify a Custom Avatar Directory
« Reply #1 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.
Liverpool FC Forum with 14 million+ posts.

Offline Something like that

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 2,496
  • Gender: Male
  • ]
Re: Big Performance Tip: Specify a Custom Avatar Directory
« Reply #2 on: October 01, 2007, 05:26:49 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.


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

Will this change also affect Alexa rankings?

Offline Ben_S

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 11,702
  • xxx
Re: Big Performance Tip: Specify a Custom Avatar Directory
« Reply #3 on: October 01, 2007, 05:38:18 AM »
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
Liverpool FC Forum with 14 million+ posts.

Offline Something like that

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 2,496
  • Gender: Male
  • ]
Re: Big Performance Tip: Specify a Custom Avatar Directory
« Reply #4 on: October 04, 2007, 10:05:11 PM »
I'm not able to move the old avatars... ::) with the hidden function.  Any other ways to do it?

Do it like I suggested in the first post :)

Offline Ben_S

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 11,702
  • xxx
Re: Big Performance Tip: Specify a Custom Avatar Directory
« Reply #5 on: October 05, 2007, 07:21:22 PM »
There is no visual confirmation, it just does it. To check just right click on the image and goto properties and see where it's located, as long as it's not index.php?somewhere then it's done.
Liverpool FC Forum with 14 million+ posts.

Offline trigi

  • Newbie
  • *
  • Posts: 9
Re: Big Performance Tip: Specify a Custom Avatar Directory
« Reply #6 on: January 02, 2008, 02:26:32 PM »
Done this, still 2 much load on the server.
Got any more ideas how to make things faster?

Do you maybe know if the 1.1.4 works faster than 1.1.1?
And another question, on wich version does SMF work best? PHP4, PHP5 or PHP5+FCGI ?

Bye, Crt

Offline Something like that

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 2,496
  • Gender: Male
  • ]
Re: Big Performance Tip: Specify a Custom Avatar Directory
« Reply #7 on: January 02, 2008, 09:52:56 PM »
Done this, still 2 much load on the server.
Got any more ideas how to make things faster?

Do you maybe know if the 1.1.4 works faster than 1.1.1?
And another question, on wich version does SMF work best? PHP4, PHP5 or PHP5+FCGI ?

Bye, Crt

PHP5+FCGI, especially if you compile APC into PHP.

Offline Owdy

  • SMF Fossil
  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 15,590
  • Gender: Male
  • W00t!
    • janoloferiksson on LinkedIn
    • @@jaoler on Twitter
Re: Big Performance Tip: Specify a Custom Avatar Directory
« Reply #8 on: January 08, 2008, 05:14:16 PM »
There is an easier way to do this using a built in hidden feature,
Why that feature is still hidden? :)
Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

Offline dukeofgaming

  • Semi-Newbie
  • *
  • Posts: 74
Re: Big Performance Tip: Specify a Custom Avatar Directory
« Reply #9 on: January 11, 2008, 11:03:45 PM »
More important... what and where are all of the hidden features =P

Offline Miyagi

  • Semi-Newbie
  • *
  • Posts: 49
  • Gender: Male
Re: Big Performance Tip: Specify a Custom Avatar Directory
« Reply #10 on: January 12, 2008, 11:31:13 PM »
thanks for the tip, have implemented. :)
FordXR5Turbo.com - Dedicated to the Ford Focus & Mondeo XR5 Turbo in Australia
FordXR4.com - Dedicated to the Ford Fiesta XR4 in Australia

Offline edi67

  • SMF Hero
  • ******
  • Posts: 1,532
  • Gender: Male
  • Italian Supporter
    • CrazyZone
Re: Big Performance Tip: Specify a Custom Avatar Directory
« Reply #11 on: January 14, 2008, 12:35:22 PM »
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.


Sorry Ben but is possible this ?
i only CREATED the directory for the avatars uploaded by users and AUTOMATICALY all avatars uploaded in paste are GOES in that specific directory without i made not action.

Is possible this ? but is real :) so i ony create AVS directory and everything was done
CrazyZone - My SMF Forum


From the difficult the hardening of the man you can see

Offline Something like that

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 2,496
  • Gender: Male
  • ]
Re: Big Performance Tip: Specify a Custom Avatar Directory
« Reply #12 on: January 14, 2008, 03:54:20 PM »
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.

That's because without a custom directory, avatars are sent as output from index.php (which most would assume spits out pages, not images).

Offline kamu8recon

  • Semi-Newbie
  • *
  • Posts: 82
Re: Big Performance Tip: Specify a Custom Avatar Directory
« Reply #13 on: March 03, 2008, 04:53:36 AM »
Ok i get up to this point and then i get lost, where do I go to run the SQL query? Do i have to go into phpmyadmin to do this? With index.php? are you referring to index.php~ ? and if so where do I insert that code if not where have i gone wrong.

Quote
Fourth, 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

Thanks for the help,
Kamu

Offline Owdy

  • SMF Fossil
  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 15,590
  • Gender: Male
  • W00t!
    • janoloferiksson on LinkedIn
    • @@jaoler on Twitter
Re: Big Performance Tip: Specify a Custom Avatar Directory
« Reply #14 on: March 04, 2008, 09:43:25 PM »

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
Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

Offline kamu8recon

  • Semi-Newbie
  • *
  • Posts: 82
Re: Big Performance Tip: Specify a Custom Avatar Directory
« Reply #15 on: March 05, 2008, 01:12:19 AM »
I have created the new directory and it is writeable, when you say access index.php? what is the question mark are you referring to ~ .and do I put everything after the questionmark  in the index.php? file, if so then where.

I'm sorry but I am completely lost on this, I have read all the previous posts and I still do not see where to go, any detailed help is much appreciated.

Kamu

Offline 青山 素子

  • Server Team
  • SMF Super Hero
  • *
  • Posts: 17,020
  • 戦場ヶ原、蕩れ!
    • srvrguy on GitHub
    • @motokochan on Twitter
    • Nekomusume Moe
Re: Big Performance Tip: Specify a Custom Avatar Directory
« Reply #16 on: March 06, 2008, 11:00:43 AM »
Browse to that URL on your site.
Motoko-chan
Director, Simple Machines

Just because it's pouring down doesn't mean we're gonna drown. There's a time when all you can say is let it rain - Mat Kearney (Let It Rain)

Note: Unless otherwise stated, my posts are not representative of any official position or opinion of Simple Machines.


Offline kamu8recon

  • Semi-Newbie
  • *
  • Posts: 82
Re: Big Performance Tip: Specify a Custom Avatar Directory
« Reply #17 on: March 06, 2008, 11:07:25 AM »
Motoko-Chan,

I am not sure what you are referring to so I just put my url here:

http://www.asskikrzrevivl.com/forum/

Offline 青山 素子

  • Server Team
  • SMF Super Hero
  • *
  • Posts: 17,020
  • 戦場ヶ原、蕩れ!
    • srvrguy on GitHub
    • @motokochan on Twitter
    • Nekomusume Moe
Re: Big Performance Tip: Specify a Custom Avatar Directory
« Reply #18 on: March 06, 2008, 11:14:52 AM »
Put "index.php?action=manageattachments;sa=moveAvatars" at the end of that in your browser.
Motoko-chan
Director, Simple Machines

Just because it's pouring down doesn't mean we're gonna drown. There's a time when all you can say is let it rain - Mat Kearney (Let It Rain)

Note: Unless otherwise stated, my posts are not representative of any official position or opinion of Simple Machines.


Offline kamu8recon

  • Semi-Newbie
  • *
  • Posts: 82
Re: Big Performance Tip: Specify a Custom Avatar Directory
« Reply #19 on: March 06, 2008, 03:15:19 PM »
I have entered that text after my url, it lead me here:

index.php?action=manageattachments;sa=maintenance

I went ahead and clicked maintain and now it doesnt show my avatars that I had before the directory change. It only shows the ones after the change.