SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Thread: file listing, scalability, optimization question.

  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    file listing, scalability, optimization question.

    wondering how scalable a script i made is. it basically reads the entire contents of a directory (ei: 001.jpg, 002.jpg, 003.jpg), determines the last file uploaded (ei: 003.jpg), adds one to the name (ei: 004.jpg), and creates the file.

    does it take a significant amount of time to process if there are to be 10000 files in that directory? if so, is there a more effecient way to achieve the same outcome?

    thanks in advance.

  2. #2
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Going through 10,000 files will certainly take a lot of time.

    Another approach would be to store the name of the last uploaded file in a file. You can then open the file get its contents (the newest file's name).

    PHP Code:
    // upload here;

    $name 'name of the uploaded file';

    // storing the name of the last uploaded file
    $fp fopen('lastuploaded''w');
    fwrite($fp$name);
    fclose($fp);

    // get the name
    $fp fopen('lastuploaded''r');
    $data fread($fpfilesize('lastuploaded'));
    fclose ($fp);

    echo 
    'last uploaded file was: '$data
    Another way would be to store the name in a database.

  3. #3
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    An even better way would be to store the image in a database, and let it handle the inidices :-)
    My name is Steve, and I'm a super-villian.

  4. #4
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Having 10.000 files in one directory will always be a performance issue, some file systems get very slow with that amount. Try to put 10.000 files into one directory on your Windows PC and load that directory in Windows Explorer (I am speaking from experience, I once had 16.000 files in one directory here on Windows XP).

    It would be better to use subdirectories and store the paths to the images in a database, so you can manage them with simple queries.

  5. #5
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have 213 Folders in My Documents and from that I have a total of 3000 Folders and 3.12Gb. Takes Windows an (ice) age for me to look through them, even just a few folders down from the root...

  6. #6
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lieut_data
    An even better way would be to store the image in a database, and let it handle the inidices :-)
    Storing the image itself in the database would be very inefficient

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  7. #7
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yer Put the IMGs to a folder and put the URL link to the database...

  8. #8
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wow thanks everyone for the tips! =)

  9. #9
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, own up - who knocked 1 point of my reputations huh ?

    I have 213 Folders in My Documents and from that I have a total of 3000 Folders and 3.12Gb. Takes Windows an (ice) age for me to look through them, even just a few folders down from the root...
    I posted the above quote more out of a sense of humour than anything else... What, has Site Point Forums become this devoid of a laugh and a joke ? If that is the case, then I'm off mate

  10. #10
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    im sorry to hear that. i wasnt even aware of the new rating feature until i read your post, i went and gave everyone a helpful rating, including you, if it may be any consolidation to you.

  11. #11
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers Micron I don't really know what the end point of the reputations is myself though the more the better I suppose ? Still think though it's a bit unfair sometimes on how anyone can knock you down for next to no reason at all...

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
  •