note 21001 added to function.mkdir
| From: | esm at vania dot dk | Date: | Wed, 24 Apr 2002 23:14:27 +0000 |
| Subject: | note 21001 added to function.mkdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-29812@lists.php.net to get a copy of this message | ||
Neat little function by gjukema@jukeware.com!
=============================================
I timed it (using PEARs benchmark class) and compared it with calling exec()
this is the lines of codes that I timed:
function ForceDirectories( $path) {
if ( strlen( $path) == 0) {
return 0;
}
//
if ( strlen( $path) < 3) {
return 1; // avoid 'xyz:\' problem.
}
elseif ( is_dir( $path)) {
return 1; // avoid 'xyz:\' problem.
}
elseif ( dirname( $path) == $path) {
return 1; // avoid 'xyz:\' problem.
}
return ( ForceDirectories( dirname( $path)) and mkdir( $path, 0775));
}
function xForceDirectories( $path) {
exec('mkdir -p ' . $path);
}
I called both functions with (SOME_DIR . '/1/2/3/4/5/6')
here are the results
1 time 100 times (avg.)
ForcedDirectories 0.0020860433578491 0.00018657803535461
xForcedDirectories 0.0098119974136353 0.0092913997173309
(create dir) (dir is already created)
Not very scientific I know, but I also know what I am going to use :)
BTW. The figures are similar on a win32 box
--
http://www.php.net/manual/en/function.mkdir.php
http://master.php.net/manage/user-notes.php?action=edit+21001
http://master.php.net/manage/user-notes.php?action=delete+21001
http://master.php.net/manage/user-notes.php?action=reject+21001