Reading: In writing procedures found in the determination of the existence of files, there are two ways to write, some people use the is_file, some people use the file_exists, which is better or more appropriate? Does the file exist in Is_file or file_exists? When writing a program, it is found that there are two ways to determine if a file exists
However, the performance of these two functions is different, is_file () is faster than file_exists ().
If the file to be checked exists, then Is_file () is many times faster than file_exists (), but if the file does not exist, the two are similar.
The following is the result of the test, the first test is the file exists, and the second is a file that does not exist:
First Test, file present
<?php //Run file_exists 10,000 times $time = Microtime (); $time = Explode (' ', $time); $begintime = $time [1] + $time [0]; for ($i =0; $i <10000; $i + +) file_exists ('/users/jacky '); File exists $time = Microtime (); $time = Explode ("", $time); $endtime = $time [1] + $time [0]; $totaltime = ($endtime-$begintime); Echo ' runs file_exists 10,000 times: '. $totaltime. ' seconds '. Php_eol; Run Is_file 10,000 times $time = Microtime (); $time = Explode ("", $time); $begintime = $time [1] + $time [0]; for ($i =0; $i <10000; $i + +) is_file ('/users/jacky '); $time = Microtime (); $time = Explode ("", $time); $endtime = $time [1] + $time [0]; $totaltime = ($endtime-$begintime); Echo ' runs Is_file 10,000 times: '. $totaltime. ' seconds. ' Php_eol;
Second Test, file does not exist
<?php//Run file_exists 10,000 times $time = Microtime (); $time = Explode (' ', $time); $begintime = $time [1] + $time [0]; for ($i =0; $i <10000; $i + +) file_exists ('/users/jackys '); File does not exist $time = Microtime (); $time = Explode ("", $time); $endtime = $time [1] + $time [0]; $totaltime = ($endtime-$begintime); Echo ' runs file_exists 10,000 times: '. $totaltime. ' seconds '. Php_eol; Run Is_file 10,000 times $time = Microtime (); $time = Explode ("", $time); $begintime = $time [1] + $time [0]; for ($i =0; $i <10000; $i + +) is_file ('/users/jackys '); $time = Microtime (); $time = Explode ("", $time); $endtime = $time [1] + $time [0]; $totaltime = ($endtime-$begintime); Echo ' runs Is_file 10,000 times: '. $totaltime. ' seconds. ' Php_eol;