Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 2 of 2 FirstFirst 1 2
Results 11 to 18 of 18
  1. #11
    Senior Member hagen's Avatar
    Join Date
    Aug 2005
    Posts
    408
    Member #
    10882
    Liked
    1 times
    yes is a good plan or simply use a file...

    in fact if you were worried about the server load you could run the above code I suggested and pipe the results into a file say once a day then use that...

    put the results into an array then use php "shuffle($array)" to randomise...

    :-)

    -Hagen
    Hagen Rose: hagen(at)jxwd(dot)co(dot)uk
    JX Web Development, Bournemouth, Dorset...JXWD.co.uk

  2.  

  3. #12
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,824
    Member #
    5580
    Liked
    726 times
    See, I never thought of the MySQL approach ...

    About getting a random image .... what if you wanted to get 3 images at
    one time. Can you get 3 random numbers without repeating one of the
    numbers?


  4. #13
    Senior Member hagen's Avatar
    Join Date
    Aug 2005
    Posts
    408
    Member #
    10882
    Liked
    1 times
    Yes MySQL... doesnt repeat with the following kind of access:

    PHP Code:
    $result mysql_query("SELECT * FROM huts ORDER BY rand($seed)") or die(mysql_error()); 
    If your'e intrested here is how I make a daily seed for the psudo random number....
    PHP Code:
    $seed str_replace("0"""date("d")) + (100 str_replace("0"""date("m"))); 

    however you do it, it's really easy to just throw the file away and get another one even if it has already been displayed...

    I do this by adding the filename to a string then using a preg_patch.... Or you could just use an array.... (The reason I use a string is I tend to pass it between pages....)

    -Hagen
    Hagen Rose: hagen(at)jxwd(dot)co(dot)uk
    JX Web Development, Bournemouth, Dorset...JXWD.co.uk

  5. #14
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    File-system access is inately slower than Database access. It is not significantly more processor intensive. It is, however, dependant on hard drive speed, vs. solid-state memory, and is therefore slower.

    Accessing a file-list from your machine vs. an array list or database will therefore be slower, but recognizably so on a typical website. I use file-access for my homepage photo gallery, with no problems whatsoever.

    You could alternatively store your file list into an array (in a php file referenced as an include, perhaps) and update that list daily. Then you'd have the best of both worlds.


  6. #15
    Senior Member hagen's Avatar
    Join Date
    Aug 2005
    Posts
    408
    Member #
    10882
    Liked
    1 times
    Hi Steve, ahhhh yes of course the database is running in the DRAM.... thanks for the reminder...

    Is it not going to get the photoes from the hard drive anyway? What about the pages? Guess there could be some caching... But an entire photo gallery? Spose its no different from haveing an entire database....

    Even better, put your actual photo binaries, instead of the file names into the database, then pull them out from there...

    (I know the ISP also caches pages to speed things up, because it can be very annoying for a designer!!...)

    The multi user question still stands... A key question for me is: is the processor waiting while it has made a request to the memory device? I would think it would be busy working on other requests...

    I would love some difinitive answers to this stuff, because its fairly core to what we do.... :-)
    Hagen Rose: hagen(at)jxwd(dot)co(dot)uk
    JX Web Development, Bournemouth, Dorset...JXWD.co.uk

  7. #16
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Well, the benefits of having the database in RAM only manifest themselves while it stays in RAM. The second your data becomes too big and parts of the database start to get swapped onto the hard drive, the benefits start to decrease significantly.

    On a related note, do databases really sit in RAM? I know the data itself is definitely stored on the hard drive, but I'm guessing the database uses algorithms to determine what parts of the db it should be keeping in RAM, since keeping everything there would be less than efficient. The biggest advantage with a database isn't, if I remember correctly, that it sits in RAM, but rather that, by analyzing your query, and by being able to load, for example, indices into RAM, it can look for the actual data on your hard drive in a more optimized fashion rather than just hunt through it to try and find what you need.

    Moreover, let's not forget the overhead that is network communications when dealing with a database server on a separate computer. While in general it's definitely true that db access is faster, it's not always as simple as that, I daresay. I'm sure certain contexts lend themselves to flat files better than to databases, just as many contexts play nice with databases.

  8. #17
    Senior Member hagen's Avatar
    Join Date
    Aug 2005
    Posts
    408
    Member #
    10882
    Liked
    1 times
    The MySQL server should normally be tuned using the: key_buffer_size to avoid the system having to page.... Sorry I dont know exactly how the key buffer relates to the database size...

    Should be less than 50% of the memory on a shared system...

    My server has 4G.... Thats a 2G key buffer.... Anyway it is BIG before swapping occurs.... obviously BIG is a term which is relative to what you normally design....

    I guess you would expect the server to go at least some times onto the hard drive to back things up, but also not entirely true.... There is a --memlock command to stop the system comming out of ram... I guess when you shut the server down it must save a restore point of some kind onto another device...

    :-)

    -Hagen
    Hagen Rose: hagen(at)jxwd(dot)co(dot)uk
    JX Web Development, Bournemouth, Dorset...JXWD.co.uk

  9. #18
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,824
    Member #
    5580
    Liked
    726 times
    Well ... that is all informative ... but ...

    My site doesn't quite get the number of visitors that Google, Ebay, or Amazon.com get.

    I'm pretty sure that accessing a few images with each refresh isn't going to kill my server.

    The scope of this tutorial was for PHP beginners that were interested in randomly
    displaying some images. So, unless you're working for Ebay, feel free to use this tutorial.



Page 2 of 2 FirstFirst 1 2

Remove Ads

Posting Permissions

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

Search tags for this page

php code for random image display

Click on a term to search for related topics.
All times are GMT -6. The time now is 10:42 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com