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