[Tutorial] [0.3.8] Send pre-compressed artwork over http [gzip + Apache]
#1

Hello guys, today I wanted to share a method that pretty much worked out a bit for me. As SA-MP has gzip support through http, this is a very good thing to take advantage of. This guide will use apache, and the files will be already compressed, as having the server to handle the compression would be a waste of CPU resources because they are static. Before staring, please make sure you have access to edit configurations of your apache server. You can edit the .conf files directly or use .htaccess files, but make sure they work!


Compressing up the models
First of all, we are going to pass gzip through all of our txd and dff files. The fastest way to do this on Linux would be with the following command. Note that this command will replace all of the files in you directory with gzipped ones.

Код:
gzip --best *
Now you'll probably end up with a a bunch of .txd.gz and dff.gz files. As .gz is already defined in the apache configuration, we'll rename them to "txdgz" and "dffgz". This command will strip off the ".gz" to all the files present in your directory:

Код:
rename 's/.gz$/gz/' *.gz
Setting up the apache server
This is an easy copy-paste part. Add to you .conf or .htacces file the following (if editing the .conf file, make sure you are in a "<VirtualHost>" or "<Directory>" clause, if you are using .htaccess then just paste it and it should work):

Код:
AddEncoding gzip .txdgz .dffgz
AddType application/octet-stream .txdgz
AddType application/octet-stream .dffgz
This will tell Apache to server the txdgz and dffgz files as Octet-Stream (generic file) with gzip encoding, so that the client (SA-MP) know that it's a compressed file. Make sure to restart the server to apply the changes.

Now you should setup your redirect download to append an extra gz to file names. If you are using the dl_redirect example, then appending "gz" at the end will work:

pawn Код:
format(fullurl,256,"%s/%sgz",baseurl,dlfilename);
I did a little comparison benchmark, you can see a bit of speed gain:

11:28 4770 Objects (LC&VC4SAMP2SA) Uncompressed
7:35 4770 Objects (LC&VC4SAMP2SA) Compressed (gzip --best)

Hope you find this useful!
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)