SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Zealot HardDriver's Avatar
    Join Date
    Feb 2004
    Location
    Kentucky, USA
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Random Images: PHP vs. Javascript

    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?

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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).

  3. #3
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A php script like:

    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] . '\">'
    Will put little to no strain on the server.

  4. #4
    SitePoint Evangelist dmsuperman's Avatar
    Join Date
    Feb 2005
    Location
    A box
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  5. #5
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by dmsuperman
    ...while JS is client specific and could cause problems for those without JS enabled.
    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.

  6. #6
    SitePoint Zealot HardDriver's Avatar
    Join Date
    Feb 2004
    Location
    Kentucky, USA
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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!

  7. #7
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem
    Last edited by Dylan B; May 14, 2005 at 05:31.

  8. #8
    SitePoint Zealot HardDriver's Avatar
    Join Date
    Feb 2004
    Location
    Kentucky, USA
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dylannn
    No problem

    Rep?
    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!

  9. #9
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, rep is an awesome feature.

  10. #10
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Dylannn
    No problem

    Rep?
    Did you actually ask for rep??

  11. #11
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •