可以直接在 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/