• Welcome to Simple Machines Community Forum. Please login or sign up.
December 05, 2021, 01:14:13 PM

News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord


Big Performance Tip: Specify a Custom Avatar Directory

Started by Something like that, September 30, 2007, 10:19:16 PM

Previous topic - Next topic

Something like that

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.
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.

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.
Liverpool FC Forum with 14 million+ posts.

Something like that

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.


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
Liverpool FC Forum with 14 million+ posts.

Something like that

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?

Do it like I suggested in the first post :)

Ben_S

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.

trigi

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

Something like that

Quote from: trigi 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

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

Owdy

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

dukeofgaming

More important... what and where are all of the hidden features =P

Miyagi

FordXR5Turbo.com - Dedicated to the Ford Focus & Mondeo XR5 Turbo in Australia
FordXR4.com - Dedicated to the Ford Fiesta XR4 in Australia

edi67

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.


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

Something like that

Quote from: Ben_S on October 01, 2007, 04:43:37 AM
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).

kamu8recon

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.

QuoteFourth, 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

Owdy

Quote from: Ben_S on October 01, 2007, 04:43:37 AM

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

kamu8recon

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

青山 素子

Motoko-chan
Director, Simple Machines

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


kamu8recon

Motoko-Chan,

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

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

青山 素子

Put "index.php?action=manageattachments;sa=moveAvatars" at the end of that in your browser.
Motoko-chan
Director, Simple Machines

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


kamu8recon

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.

Advertisement: