unique file name

Discussion in 'PHP' started by beermaker74, Feb 11, 2007.

  1. #1
    ok here is the plan. I have a slideshow that works off dynamically created xml. right now i have the name = to time() so I have a unique filename for each xml. Somebody mentioned that if 2 people request the same xml that a conflict will occur. Here is the reason I chose the time to name the file. I am going to set up a cron job to delete the old xml files. I planned on just subtracting an hour from the current time and comparing the old xml files against that time. then deleting them. so now to the meat. what is the best way to name the xml files so that they are unique and be able to run a cron to delete them after they are no longer needed? i was thinking of using the time and then maybe an underscore then some random sequence. I was hoping that I would then be able to find them and delete them witht the cron job. If anybody has any suggestions as to the most efficient way to handle this, please let me know. I hope I explained everything well enough. Also all my xml files that I want to delete are in one folder called you guessed it xml. I appreciate the help
     
    beermaker74, Feb 11, 2007 IP
  2. rays

    rays Active Member

    Messages:
    563
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #2
    i guess your approach is the best solutions for all the issues ... i will suggest to use microtime so that there will not be an issues about concurrent users accessing and writing file
     
    rays, Feb 11, 2007 IP
  3. wenzlerpaul

    wenzlerpaul Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I agree with rays, use microtime, but if you still are worried of conflict, use microtime and random at the end, you can also assign an underscore between time and rand. There is a gazillion to one chance that there will be 2 or more person getting the same time and same randomized code at the end. Now to make it a little bit farther to the edge, use numbers and letters and uppercase and lowercase on your random number, then look for dups using error traps (if duplicate exists, add an additional character to the filename, this will eliminate the chance of any duplication). although i find that the last is already exagerrated approach hehe.
     
    wenzlerpaul, Feb 12, 2007 IP