首页 > 解决方案 > 触发inotify事件时如何运行php代码

问题描述

每当在 php 中更新文件(log.txt)时,我都会尝试重新加载框架。我想我可以用inotify_add_watch($inf, './log.txt', IN_MODIFY);.

问题是,我是一个完整的 php 菜鸟,而文档对此没有帮助。当文件 IN_MODIFY 事件被触发时,我将如何运行一些代码?

到目前为止,我有

<html style='background-color:#202020;'>
  <word style='color:#FFFFFF;'>
  <head>
    <meta http-equiv="refresh" content="2"/>
  </head>
  <body id="chat">
  <?php
    $log = file_get_contents('./log.txt');
    echo $log;
    $inf = inotify_init();
    $watch = inotify_add_watch($inf, './log.txt', IN_MODIFY);
    $events = inotify_read($inf);
    //Run php code here when inotify event occurs

    inotify_rm_watch($inf, $watch);
    fclose($inf);
  ?>
 </body>
</html>

如您所见,我设置了监视描述符和 inotify 实例,但我不知道如何使用该事件。

有任何想法吗?

标签: phpinotify

解决方案


推荐阅读