Liquid Fire Posted February 23, 2008 Share Posted February 23, 2008 I have built a framework and right now am trying to find any type of speed issue/bottleneck and think i found my big one. I have a recursive directory search function <?php function check_for_file($directory, $file_name) { //get the directory handle $directory_handle = opendir($directory); while($resource = readdir($directory_handle)) { //make sure it is not a dotted directory if(!is_dot($resource)) { if(is_dir($directory . '/' . $resource)) { //we need to call ourself if this is a directory $search_result = check_for_file($directory . '/' . $resource, $file_name); if($search_result !== false ) { return $search_result; } } else { //let check to see if this is the file if(file_exists($directory . '/' . $file_name)) { return $directory . '/' . $file_name; } } } } return false; } ?> now in there are 6 folders and about 35-40 files to search and out of the total .56 second it takes to load the data from my framework, .40 is taken up inside this function. does anyone see where i can optimise my code? Link to comment https://forums.phpfreaks.com/topic/92537-recursive-directory-search/ Share on other sites More sharing options...
Liquid Fire Posted February 23, 2008 Author Share Posted February 23, 2008 why can't i edit my post? anyways, also if there is a better way to do the auto load where i don't have to worry about put every directory in class file paths and still allows me to organize my files into a clean directory structure. Link to comment https://forums.phpfreaks.com/topic/92537-recursive-directory-search/#findComment-474167 Share on other sites More sharing options...
Liquid Fire Posted February 23, 2008 Author Share Posted February 23, 2008 anyone? Link to comment https://forums.phpfreaks.com/topic/92537-recursive-directory-search/#findComment-474436 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.