Feature #403 » monitor-fam.php
| 1 |
<?php
|
|---|---|
| 2 |
|
| 3 |
$path = "/tmp/test.txt"; |
| 4 |
|
| 5 |
function print_file() |
| 6 |
{
|
| 7 |
echo("\n ****"); |
| 8 |
echo(file_get_contents($path)); |
| 9 |
echo("\n"); |
| 10 |
}
|
| 11 |
|
| 12 |
// create base and event
|
| 13 |
$famd = fam_open(); |
| 14 |
if ($famd === FALSE) { |
| 15 |
print("could not connect to famd\n"); |
| 16 |
}
|
| 17 |
|
| 18 |
$mon = fam_monitor_file($famd, $path); |
| 19 |
if ($mon === FALSE) { |
| 20 |
print("failed to setup file monitor\n"); |
| 21 |
}
|
| 22 |
|
| 23 |
while(TRUE) { |
| 24 |
$result = fam_next_event($famd); |
| 25 |
if ($result['code'] == FAMChanged) { |
| 26 |
print_file(); |
| 27 |
}
|
| 28 |
}
|
| 29 |
?>
|
| 30 |
|