ala888 Posted July 15, 2014 Share Posted July 15, 2014 Im making a webserver that for every file received, finds a randomly generated folder name, checks if it already exists; and if it does not, it puts the files in there.But what if multiple instances are running at the same time, and by the luck of the draw, more than one batch of files gets dumped into the same folder since all the php instances though it didnt exist at the exact same time?Is there any way to prevent this? Link to comment Share on other sites More sharing options...
ala888 Posted July 15, 2014 Author Share Posted July 15, 2014 (edited) To clarify my question, I am first checking if a file directory exists via file_exists in php, before creating and inserting uploaded files into it. However, since the server is a multithreaded one, I am afraid that two instances of the script might somehow check the same file name at the same type, before running into each other. Edited July 15, 2014 by ala888 Link to comment Share on other sites More sharing options...
Don Jajo Posted July 15, 2014 Share Posted July 15, 2014 well, in this instance i use something like uniqid() function which is generated based on microtime - http://www.w3schools.com/php/func_misc_uniqid.asp Then do something like md5(uniqid()) or sha1 I don't think its gonna clash since time changes every second Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now