fclose($file_handle); // stat of the file created $file_stat = stat($filename); sleep(2); // now new stat of the dir after file is created $new_dir_stat = stat($dirname); clearstatcache(); // stat contains 13 different values stored twice, can be accessed using // numeric and named keys, compare them to see they are same echo "*** Testing stat(): validating the values stored in stat ***\n"; // Initial stat values var_dump(compare_self_stat($file_stat)); //expect true var_dump(compare_self_stat($dir_stat)); //expect true // New stat values taken after creation of file var_dump(compare_self_stat($new_dir_stat)); // expect true // compare the two stat values, initial stat and stat recorded after // creating file, also dump the value of stats echo "*** Testing stat(): comparing stats (recorded before and after file creation) ***\n"; echo "-- comparing difference in dir stats before and after creating file in it --\n"; $affected_elements = array(9, 'mtime'); var_dump(compare_stats($dir_stat, $new_dir_stat, $affected_elements, '!=', true)); // expect true echo "*** Testing stat(): for the return value ***\n"; var_dump(is_array(stat($filename))); echo "\n---Done---"; $file_path = dirname(__FILE__); unlink("{$file_path}/stat_basic/stat_basic.tmp"); rmdir("{$file_path}/stat_basic");
$dirname = "{$file_path}/stat_variation3"; $old_stat = stat($dirname); clearstatcache(); sleep(2); mkdir("{$dirname}/stat_variation3_subdir"); $file_handle = fopen("{$dirname}/stat_variation3a.tmp", "w"); fclose($file_handle); $new_stat = stat($dirname); // compare self stats var_dump(compare_self_stat($old_stat)); var_dump(compare_self_stat($new_stat)); // compare the stats $affected_members = array(9, 'mtime'); clearstatcache(); sleep(2); var_dump(compare_stats($old_stat, $new_stat, $affected_members, "<")); unlink("{$dirname}/stat_variation3a.tmp"); rmdir("{$dirname}/stat_variation3_subdir"); clearstatcache(); // comparing stats after the deletion of subdir and file echo "-- Testing stat() for comparing stats after the deletion of subdir and file --\n"; $new_stat1 = stat($dirname); // compare self stats var_dump(compare_self_stat($new_stat1)); // compare the stats var_dump(compare_stats($new_stat, $new_stat1, $all_stat_keys, "=")); clearstatcache(); echo "\n*** Done ***"; ?>
/* test the effects of is_link() on stats of hard link */ $file_path = dirname(__FILE__); require "{$file_path}/file.inc"; /* create temp file & link */ $filename = "{$file_path}/lstat_stat_variation14.tmp"; $fp = fopen($filename, "w"); // temp file fclose($fp); echo "*** Checking lstat() and stat() on hard link ***\n"; $linkname = "{$file_path}/lstat_stat_variation14_hard.tmp"; //ensure that link doesn't exists @unlink($linkname); // create the link var_dump(link($filename, $linkname)); $file_stat = stat($filename); $link_stat = lstat($linkname); // compare self stats var_dump(compare_self_stat($file_stat)); var_dump(compare_self_stat($link_stat)); // compare the stat var_dump(compare_stats($file_stat, $link_stat, $all_stat_keys)); // clear the stat clearstatcache(); echo "\n--- Done ---"; ?> <?php error_reporting(0); $file_path = dirname(__FILE__); unlink("{$file_path}/lstat_stat_variation14_hard.tmp"); unlink("{$file_path}/lstat_stat_variation14.tmp");