On an extremely busy, PHP/MySQL intensive site, would a Javascript or PHP random image generator be best? The image will be loaded on every single page view. Does a PHP script like this put a serious strain on the server?
| SitePoint Sponsor |

On an extremely busy, PHP/MySQL intensive site, would a Javascript or PHP random image generator be best? The image will be loaded on every single page view. Does a PHP script like this put a serious strain on the server?
The work PHP has to do to pick a random image is pretty insignificant. If the server is really busy, a bigger problem will be having to serve numerous different pictures (cuz the browser might not have the picture selected already stored in its cache).
A php script like:
Will put little to no strain on the server.PHP Code:$pictures = array("picture1.jpg", "another.gif", "onemore.png", "hello.bmp");
$imagecount = count($pictures);
$rand = rand(0, $imagecount - 1);
echo '<image src =\"' . $pictures[$rand] . '\">';



PHP would be your best bet, as it would require pretty much 0 server strain, while JS is client specific and could cause problems for those without JS enabled.
<(^.^<) \(^.^\) (^.^) (/^.^)/ (>^.^)>
Core 2 Duo E8400 clocked @ 3.375GHz, 2x2GB 800MHz DDR2 RAM
5x SATA drives totalling 2.5TB, 7900GS KO, 6600GT

That's the key right there. With a PHP solution you virtually make this available to 100% of your audience. With JavaScript you eliminate a small percentage of users who do not have JavaScript enabled in their browsers.Originally Posted by dmsuperman
John Conde | Facebook | Twitter
Brainyminds Merchant Account Services I Love Code eBook Giant
Authorize.Net: AIM API | ARB API | CIM API Get the FREE code!
Merchant Accounts 101 | Ecommerce 101

Great, I think PHP sounds like the way to go then. Thanks for all the advice everyone, and thanks for the code as well, Dylannn!![]()
No problem![]()
Last edited by Dylan B; May 14, 2005 at 05:31.

Oh, cool, took me a second to figure out what you were talking about. It's nice to finally have a way to reward all of the helpful people here!Originally Posted by Dylannn
Yeah, rep is an awesome feature.

Did you actually ask for rep??Originally Posted by Dylannn
![]()
John Conde | Facebook | Twitter
Brainyminds Merchant Account Services I Love Code eBook Giant
Authorize.Net: AIM API | ARB API | CIM API Get the FREE code!
Merchant Accounts 101 | Ecommerce 101
I was simply informing him on the repgiving capabilities of vBulletin v3.0.3. It was his interpretation of said word to give said rep.
or something.
Last edited by Dylannn; Apr 28, 2005 at 22:29.
Bookmarks