note 108420 added to function.stream-resolve-include-path

From: Date: Wed, 25 Apr 2012 13:25:20 +0000
Subject: note 108420 added to function.stream-resolve-include-path
Groups: php.notes 
Request: Send a blank email to php-notes+get-187335@lists.php.net to get a copy of this message
I decided to run a test to see if it was true that this function, despite it's entirely different purpose, could be used as a faster more efficient file_exists. I even tested against a scenario where the current path being sought was not part any include path currently set on the system, and both functions performed as if they were intended to provide whether a file existed or not. Here is the test code (its a bit of a mess, but it gets the job done): <?php echo "Current Include Path: " . get_include_path() . "<br /><br />\n\n"; $st = microtime(true); $data = file_exists('Templates/Styles/main.css'); $et = microtime(true); var_dump($data); echo " <strong>FROM</strong> file_exists('Templates/Styles/main.css')<br />\n"; echo "Completed in : " . ($et - $st) . " seconds<br />\n"; $st = microtime(true); $data = stream_resolve_include_path('Templates/Styles/main.css'); $et = microtime(true); var_dump($data); echo " <strong>FROM</strong> stream_resolve_include_path('Templates/Styles/main.css')<br />\n"; echo "Completed in : " . ($et - $st) . " seconds<br />\n"; $st = microtime(true); $data = file_exists('Templates/NotADir/NoFileHere.php'); $et = microtime(true); var_dump($data); echo " <strong>FROM</strong> file_exists('Templates/NotADir/NoFileHere.php')<br />\n"; echo "Completed in : " . ($et - $st) . " seconds<br />\n"; $st = microtime(true); $data = stream_resolve_include_path('Templates/NotADir/NoFileHere.php'); $et = microtime(true); var_dump($data); echo " <strong>FROM</strong> stream_resolve_include_path('Templates/NotADir/NoFileHere.php')<br />\n"; echo "Completed in : " . ($et - $st) . " seconds<br />\n"; ?> On my server I got the following results: Current Include Path: .:<!--REMOVED-->/lib/php:<!--REMOVED-->/lib/php bool(true) FROM file_exists('Templates/Styles/main.css') Completed in : 4.1E-5 seconds string(51) "<!--REMOVED-->/Templates/Styles/main.css" FROM stream_resolve_include_path('Templates/Styles/main.css') Completed in : 2.19345092773E-5 seconds bool(false) FROM file_exists('Templates/NotADir/NoFileHere.php') Completed in : 4.05311584473E-6 seconds bool(false) FROM stream_resolve_include_path('Templates/NotADir/NoFileHere.php') Completed in : 2.19345092773E-5 seconds Not only does this show that this is a great replacement for file_exists, it also performs twice as fast. I ran this a few times and under most tests stream_resolve_include_path ranged from 2.1 to 2.8 while file_exists ranged from 4.0 to 5.8 so stream_resolve tended to have much more consistent performance over time as well. ---- Server IP: 216.235.13.26 Probable Submitter: 24.109.211.98 ---- Manual Page -- http://www.php.net/manual/en/function.stream-resolve-include-path.php Edit -- https://master.php.net/note/edit/108420 Del: integrated -- https://master.php.net/note/delete/108420/integrated Del: useless -- https://master.php.net/note/delete/108420/useless Del: bad code -- https://master.php.net/note/delete/108420/bad+code Del: spam -- https://master.php.net/note/delete/108420/spam Del: non-english -- https://master.php.net/note/delete/108420/non-english Del: in docs -- https://master.php.net/note/delete/108420/in+docs Del: other reasons-- https://master.php.net/note/delete/108420 Reject -- https://master.php.net/note/reject/108420 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#187335) next »