![]() |
You don't always need php (POTD Script)
Had an issue with a client machine yesterday, load was skyrocketing on their machine due to a large number of hits on a POTD script. The script used readfile to send the thumbnail to the affiliate site and I'm guessing it was done this way because it was modified from an earlier version of the script.
First, the words Picture of the Day mean that you need to make that decision once per day. There is no reason to decide which picture to display on each pageload. A cron job will take care of running things once a day and you can save quite a bit of load on your server. What their html looked like: The relevent part of the php script Code:
Now, they do use a script to rotate in the correct thumbnails once a day, so, they avoid the date calculation on every POTD load, however, readfile in php is slower than apache serving the page. Of course, they could have done a location redirect to the final destination of the page, but, that would have been additional load on Apache. Most people use mod_rewrite to handle hotlinking, but, that isn't all that mod_rewrite can do. To ease the load and maintain compatibility with all of the other sites out there that had the existing POTD code on their websites, I wrote a rule that would rewrite the url and serve the picture without ever hitting php, but, if the rule didn't match, the php script would handle it. This client had a number of sites using that code, so, there was some validation to do inside the rule to make sure we were sending the data correctly. The end result was a short mod_rewrite rule that handled the requests that matched the first rule, and dropped through to their script to be handled if the URL didn't match the rules. PHP only gets hit when the request falls through the rule and therefore the load dropped almost instantly. The rule that eliminated php: Code:
RewriteEngine on Code:
updates/tn1asdf.jpg It would have been preferrable for the html code to look something like: completely eliminating the need for php to handle the thumbnail image and allowing the script to handle the fullsized image. How the rewrite rule works: Code:
RewriteEngine on If [R] had been set, apache wouldn't have silently served the image but done a redirect to the new location. |
hi cd34 must be nice to have all that knowledge :D
Fred |
so what you did is make static images now rather then to create them with php? (btw I have better experience with fpassthru rather then reading and outputing the data)
also I think on most browsers this only affects the first load of the image.. If the URL to the image doesnt change then it should get cached |
actually, the images were static before, but served via readfile. fpassthru is indeed better, but, in reality, there was no reason for any of that processing at all.
And if you use fpassthru or readfile, it sets the expire time and is not cached. |
yeah ofcourse they were static before.. what I rather ment was availible staticly for the user
I use this for hotlinking-protection (so you cant even hotlink by using a script..) it also might have been interesting for you so users with some pc-knowledge cant look at the images that are intended for the next couple days recreating the images is only needed if it is vital to keep away bandwidth-hogs about the expire-time: perhaps with special headers...? I'll look that up EDIT: header("Cache-Control: ......... ;) |
If you use a script to copy the picture to a predefined location, the source location is hidden.
And typically sponsor programs want their POTD thumbnail to be hotlinkable. |
If you're rotating the pic each day a really simple and fast way is to use the date variables in rewrite. This example is from a guy who wanted 7 pics, so they would repeat each week. You can change the variable to rotate through 31 pics, one for each day of the month, or 366 pics, one for each day of the year. The HTML code: |
Nice quickfix man :D
|
I have no skills with mod_rewrite :(
So, I would make changes in the rattion PHP script. On rotation the filepaths would be /update/potd/site1/1.jpg 2.jpg, etc - for direct linking to the image AND I would deff kill the old PHP script. I think, the way you made your mod_rewrite, if the Query String is: type=thumb1&site=site1 The rewrite will fail. |
I am worried about messing with the mod rewrite too. But i certainly could use a better potd script. Im going to play with this.
|
All times are GMT -4. The time now is 03:15 AM. |
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc