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