News:

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

Main Menu

Make the attachments static and move them to another domain?

Started by Romanj, April 01, 2015, 11:55:25 AM

Previous topic - Next topic

Romanj

I have SMF forum collected about 70K of attachments (almost all of them are photos) over the years. Over 20 Gb of disk space. So it's relatively huge amount of the attachments)

Recently I got an idea. What if I would take most of that attachments, lets say 50-60K, old ones, make them static, and move them to some other domain or subdomain. By static I mean to use them as any external picture through basic tag [ img ][ /img ]. So then that attachments wouldn't be a direct part of the forum anymore.

Benefits I would possibly get from that action:
- Lessen the payments to the main hosting-provider. Because, a hostings for static files are cheaper, than use of a high-performance tariff with a lot of additional disk space.
- Lessen the quantity of DB queries. Therefore - better performance of the forum, better loading time, especially for pages with lot of attachments.

So, my question is - is it possible to do that? (I'm asking it because I have a very basic knowledge of MySQL and BD structure of SMF)

Very raw plan:
1. Get the table with filenames at the attachment folders (94799_8d8536ef59b4582e3a259b18a3d2f06cf2a7a6bc format) that match the id of messages they attached to. (Something like filename - message id - other attributes)
2. Rename the files to something like photo_xxxxxx.jpg and move them to the other domain. Delete DB entries for that attachments.
3. Add to the text of the messages (by id) tags that match external picture (like [ img ]photo_xxxxxx.jpg[ /img ]) that was in that message as an attachment before.

To be more clear - I'd like to do it once, or may be once a year or so. Manually, with some MySQL queries.


Thanks!

margarett

It is certainly possible, but honestly, not for the fainted heart :P

The biggest problem you would have is to dynamically move them to another domain (if that is not on the same server). PHP can't do that on its own, you will *always* need an API to do that.
Alternatively, you will require a manual upload of the files (which should take you a decent amount of time :P ) and, for some time, twice the disk space (or breaking your attachments during the process)

In short (second possibility of course):
* Get the ID, hashed filename, mime type and extension from the database
* For each fetched file, move it elsewhere (in the same server) and rename it according a certain pattern as you suggest (meanwhile your attachments are broken)
*** Manually move the "moved files folder" from this temporary location to your static files host
After successful upload:
* Get the posts which have attachments in the "affected" range
* For each corresponding post, get the attachment IDs
** For each attachment, insert the corresponding img tag (at the end of the post?), and remove related attachments from the "attachments" table.

This is also extremely server intensive so it should be done with some pauses along the way, which clearly makes the process more difficult to code...

An extra problem that you can get from this is that your images name pattern is easily discoverable (that's why we used hashed filenames ;) ). So someone can easily drain a lot of bandwidth from you, certainly causing your "static" host to shut you down...
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Advertisement: