Return to 005_variation-win32.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / file |
1.1 misho 1: --TEST-- 2: Test fileatime(), filemtime(), filectime() & touch() functions : usage variation 3: --SKIPIF-- 4: <?php 5: if (substr(PHP_OS, 0, 3) != 'WIN') { 6: die('skip Windows-only test'); 7: } 8: ?> 9: --FILE-- 10: <?php 11: /* 12: Prototype: int fileatime ( string $filename ); 13: Description: Returns the time the file was last accessed, or FALSE 14: in case of an error. The time is returned as a Unix timestamp. 15: 16: Prototype: int filemtime ( string $filename ); 17: Description: Returns the time the file was last modified, or FALSE 18: in case of an error. 19: 20: Prototype: int filectime ( string $filename ); 21: Description: Returns the time the file was last changed, or FALSE 22: in case of an error. The time is returned as a Unix timestamp. 23: 24: Prototype: bool touch ( string $filename [, int $time [, int $atime]] ); 25: Description: Attempts to set the access and modification times of the file 26: named in the filename parameter to the value given in time. 27: */ 28: 29: /* 30: Prototype: void stat_fn(string $filename); 31: Description: Prints access, modification and change times of a file 32: */ 33: function stat_fn( $filename ) { 34: echo "-- File access time is => "; 35: print( @date( 'Y:M:D:H:i:s', fileatime($filename) ) )."\n"; 36: clearstatcache(); 37: echo "-- File modification time is => "; 38: print( @date( 'Y:M:D:H:i:s', filemtime($filename) ) )."\n"; 39: clearstatcache(); 40: echo "-- inode change time is => "; 41: print( @date( 'Y:M:D:H:i:s', filectime($filename) ) )."\n"; 42: clearstatcache(); 43: 44: } 45: 46: echo "*** Testing fileattime(), filemtime(), filectime() & touch() : usage variations ***\n"; 47: $file_path = dirname(__FILE__); 48: // create files 49: $file_handle = fopen("$file_path/005_variation1.tmp", "w"); 50: fclose($file_handle); 51: stat_fn("$file_path/005_variation1.tmp"); 52: sleep(2); 53: 54: $file_handle = fopen("$file_path/005_variation2.tmp", "w"); 55: fclose($file_handle); 56: stat_fn("$file_path/005_variation2.tmp"); 57: sleep(2); 58: 59: $file_handle = fopen("$file_path/005_variation3.tmp", "w"); 60: fclose($file_handle); 61: stat_fn("$file_path/005_variation3.tmp"); 62: 63: // delete files 64: unlink("$file_path/005_variation1.tmp"); 65: unlink("$file_path/005_variation2.tmp"); 66: unlink("$file_path/005_variation3.tmp"); 67: 68: echo "\n-- Checking different times, just after creating the file --\n"; 69: $file_name = "$file_path/005_variation1.tmp"; 70: $file_write_handle = fopen($file_name, "w"); 71: fclose($file_write_handle); 72: stat_fn($file_name); 73: sleep(2); 74: 75: /* filectime + 2 */ 76: echo "\n-- Checking different times, after changing the file permission --\n"; 77: chmod($file_name, 0777); 78: stat_fn($file_name); 79: sleep(2); 80: 81: /* filemtime + 2 & filectime + 2 */ 82: echo "\n-- Checking different times, after writing into the file --\n"; 83: $file_write_handle = fopen($file_name, "w"); 84: fwrite($file_write_handle, b"Hello, world"); 85: fclose($file_write_handle); 86: stat_fn($file_name); 87: sleep(2); 88: 89: /* fileatime + 2 */ 90: echo "\n-- Checking different times, after reading from the file --\n"; 91: $file_read_handle = fopen($file_name ,"r"); 92: fread($file_read_handle, 10); 93: fclose( $file_read_handle); 94: stat_fn($file_name); 95: sleep(2); 96: 97: /* No change */ 98: echo "\n-- Checking different times, after making a copy of the file --\n"; 99: $file_copy = "$file_path/005_variation_copy.tmp"; 100: copy($file_name, $file_copy); 101: stat_fn($file_name); 102: sleep(2); 103: 104: /* fileatime + 2 */ 105: echo "\n-- Checking different times, after performing is_file() operation on the file --\n"; 106: is_file($file_name); 107: stat_fn($file_name); 108: sleep(2); 109: 110: 111: echo "\n*** Testing touch() function with different time values ***\n"; 112: $file_name2 = $file_path."/005_variation_touch.tmp"; 113: $file_handle = fopen($file_name2, "w"); 114: fclose($file_handle); 115: sleep(2); 116: 117: /* Time is not mentioned */ 118: var_dump( touch($file_name2) ); //set to current system time 119: stat_fn($file_name2); 120: sleep(2); 121: 122: /* set to access(creation time of the file) time */ 123: var_dump( touch($file_name2, @date(fileatime($file_name2))) ); 124: stat_fn($file_name2); 125: sleep(2); 126: 127: /* set to access time of $file_name2 */ 128: var_dump( touch($file_path."/005_variation_touch_fly.tmp", @date(fileatime($file_name2)), time()) ); 129: stat_fn($file_name2); 130: sleep(2); 131: 132: /* set to default value, with Invalid timestamps */ 133: var_dump( touch($file_name2, 10) ); 134: stat_fn($file_name2); 135: var_dump( touch($file_name2, 10, 20) ); 136: stat_fn($file_name2); 137: 138: /* touch() after renaming the file */ 139: rename($file_name2, "$file_path/005_variation_touch_new.tmp"); 140: stat_fn("$file_path/005_variation_touch_new.tmp"); 141: 142: echo "Done\n"; 143: ?> 144: --CLEAN-- 145: <?php 146: $file_path = dirname(__FILE__); 147: unlink($file_path."/005_variation_softlink.tmp"); 148: unlink($file_path."/005_variation_hardlink.tmp"); 149: unlink($file_path."/005_variation1.tmp"); 150: unlink($file_path."/005_variation_copy.tmp"); 151: unlink($file_path."/005_variation_touch.tmp"); 152: unlink($file_path."/005_variation_touch_fly.tmp"); 153: unlink($file_path."/005_variation_touch_new.tmp"); 154: ?> 155: --EXPECTF-- 156: *** Testing fileattime(), filemtime(), filectime() & touch() : usage variations *** 157: -- File access time is => %d:%s:%s:%d:%d:%d 158: -- File modification time is => %d:%s:%s:%d:%d:%d 159: -- inode change time is => %d:%s:%s:%d:%d:%d 160: -- File access time is => %d:%s:%s:%d:%d:%d 161: -- File modification time is => %d:%s:%s:%d:%d:%d 162: -- inode change time is => %d:%s:%s:%d:%d:%d 163: -- File access time is => %d:%s:%s:%d:%d:%d 164: -- File modification time is => %d:%s:%s:%d:%d:%d 165: -- inode change time is => %d:%s:%s:%d:%d:%d 166: 167: -- Checking different times, just after creating the file -- 168: -- File access time is => %d:%s:%s:%d:%d:%d 169: -- File modification time is => %d:%s:%s:%d:%d:%d 170: -- inode change time is => %d:%s:%s:%d:%d:%d 171: 172: -- Checking different times, after changing the file permission -- 173: -- File access time is => %d:%s:%s:%d:%d:%d 174: -- File modification time is => %d:%s:%s:%d:%d:%d 175: -- inode change time is => %d:%s:%s:%d:%d:%d 176: 177: -- Checking different times, after writing into the file -- 178: -- File access time is => %d:%s:%s:%d:%d:%d 179: -- File modification time is => %d:%s:%s:%d:%d:%d 180: -- inode change time is => %d:%s:%s:%d:%d:%d 181: 182: -- Checking different times, after reading from the file -- 183: -- File access time is => %d:%s:%s:%d:%d:%d 184: -- File modification time is => %d:%s:%s:%d:%d:%d 185: -- inode change time is => %d:%s:%s:%d:%d:%d 186: 187: -- Checking different times, after making a copy of the file -- 188: -- File access time is => %d:%s:%s:%d:%d:%d 189: -- File modification time is => %d:%s:%s:%d:%d:%d 190: -- inode change time is => %d:%s:%s:%d:%d:%d 191: 192: -- Checking different times, after performing is_file() operation on the file -- 193: -- File access time is => %d:%s:%s:%d:%d:%d 194: -- File modification time is => %d:%s:%s:%d:%d:%d 195: -- inode change time is => %d:%s:%s:%d:%d:%d 196: 197: *** Testing touch() function with different time values *** 198: bool(true) 199: -- File access time is => %d:%s:%s:%d:%d:%d 200: -- File modification time is => %d:%s:%s:%d:%d:%d 201: -- inode change time is => %d:%s:%s:%d:%d:%d 202: bool(true) 203: -- File access time is => %d:%s:%s:%d:%d:%d 204: -- File modification time is => %d:%s:%s:%d:%d:%d 205: -- inode change time is => %d:%s:%s:%d:%d:%d 206: bool(true) 207: -- File access time is => %d:%s:%s:%d:%d:%d 208: -- File modification time is => %d:%s:%s:%d:%d:%d 209: -- inode change time is => %d:%s:%s:%d:%d:%d 210: bool(true) 211: -- File access time is => %d:%s:%s:%d:%d:%d 212: -- File modification time is => %d:%s:%s:%d:%d:%d 213: -- inode change time is => %d:%s:%s:%d:%d:%d 214: bool(true) 215: -- File access time is => %d:%s:%s:%d:%d:%d 216: -- File modification time is => %d:%s:%s:%d:%d:%d 217: -- inode change time is => %d:%s:%s:%d:%d:%d 218: -- File access time is => %d:%s:%s:%d:%d:%d 219: -- File modification time is => %d:%s:%s:%d:%d:%d 220: -- inode change time is => %d:%s:%s:%d:%d:%d 221: Done