Comment detail

ファイル更新の監視 (Nested Flatten)

	
 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
<?php
$filename = "testfile.txt";
$sleepTime = 1; //micro seconds

if (!($modifiedTimeOld = get_file_modified_time($filename))) {
    exit("File not found.");
}

while (true) {
    clearstatcache();
    
    if (!($modifiedTimeNew = get_file_modified_time($filename))) {
        exit("File not found.");
    }
    
    if ($modifiedTimeOld != $modifiedTimeNew) {
        echo "modified!\n";
        $modifiedTimeOld = $modifiedTimeNew;
    }
    
    usleep($sleepTime);
}

function get_file_modified_time($filename) {
    if (check_file_exist($filename)) {
        return filemtime($filename);
    } else {
        return false;
    }
}

function check_file_exist($filename) {
    if (!(file_exists($filename) && is_file($filename))) {
        return false;
    }
    return true;
}

Index

Feed

Other

Link

Pathtraq

loading...