I was wondering if PHP had something similar to Python's tempdir.mkdtemp(). PHP's System::mktemp seems to be unsuitable if that code is still used for it. I guess I could implement the same functionality as provided in Python myself, but I can hardly belief that I'm the only one who has seeked for that functionality and would like to avoid reinventing the wheel.
The code should be operating system agnostic, therefore using exec as suggested at https://stackoverflow.com/a/17280327/1078224 is not an option.
<?
if is_dir("myNewDir"){
//rename the directory your trying to make and do it again
}else{
mkdir("myNewDir);
}
?>
I'm not sure this is exactly as hard as making a wheel.
EDIT:
<?php
$dirName = substr(md5(mt_rand()), 0, 8);
while (@mkdir($dirName) === false){
$dirName = substr(md5(mt_rand()), 0, 0);
}
echo "Created directory: " . $dirName ;
?>
This should result in no race.