Home >php教程 >php手册 >Tail for php,php实现tail命令

Tail for php,php实现tail命令

WBOY
WBOYOriginal
2016-06-06 19:39:291429browse

监控文件变化,可以通过tail,inotify来实现,也可以通过awk转发变化的内容到外部命令中。 下面是通过popen来调用系统命令,性能内存开销相对比较

监控文件变化,可以通过tail,inotify来实现,也可以通过awk转发变化的内容到外部命令中。

下面是通过popen来调用系统命令,性能内存开销相对比较小。(转)

$handle = popen("tail -f /var/log/your_file.log 2>&1", 'r');
while(!feof($handle)) {
$buffer = fgets($handle);
echo "$buffer\n";
flush();
}
pclose($handle);

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn