php - 监听文件夹和文件(更改)

标签 php file node.js directory listen

可以直接在 PHP 或 Node 上监听文件夹和文件更改(通过事件),还是我需要创建自己的方法来执行此操作?

示例:我需要监听文件夹/user。例如,如果我将一些文件添加到此目录中,PHP 或 Node 就会接收信息并运行 PathEvent::fileAdded("/user/user.profile") 。如果我重命名一个文件夹,它会运行 PathEvent::pathRenamed("/user/save1", "/user/save2")

我知道 PHP 没有像 Node 这样的事件系统。但对于 PHP,例如,我可以运行一个方法(我目前不知道),该方法自上次检查以来发生了更改。

嗯...我只需要一种开始搜索的方法,我不知道这个搜索的确切术语是什么。如果你能给我举一个例子,那就太好了! :P

最佳答案

Node.js 提供了此功能。您可以阅读此内容 here .

简单的例子:

var fs = require('fs');

fs.watch('somedir', function (event, filename) {
    console.log(event);
    console.log(filename);
});

注意:

When watching a directory, providing filename argument in the callback is not supported on every platform (currently it's only supported on Linux and Windows). Even on supported platforms filename is not always guaranteed to be provided. Therefore, don't assume that filename argument is always provided in the callback, and have some fallback logic if it is null.

关于php - 监听文件夹和文件(更改),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9628074/

相关文章:

php - jquery中点击刷新页面如何显示之前的结果?

java - 我如何标记读取的文件以避免在java中再次读取它们?

java - 如何检查文本文件是否包含字符串?

javascript - 使用 Node JS 和 MongoDB 过滤查询

php - Yii zii.widgets.CMenu 多级子菜单的 css

php - MySQL - 具有多个模式的数据库,其中表名和列名不同

php - 如何使用 Laravel Migrations 在 Mysql 列中添加注释

c# - 将文件从 Java 发送到 C#

node.js - Redis 不在 express-session 上工作

node.js - 如何通过 IntelliJ 运行/调试配置让 wdio 运行?