文件夹监视和事件触发根据php中的文件夹状态 [英] Folder monitoring and event triggering according to folder status in php

查看:160
本文介绍了文件夹监视和事件触发根据php中的文件夹状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个文件夹,当事件发生时,xml文件在没有特定时间被复制。我想要一个php方式检查文件夹的状态,当一个xml文件到达时,会触发一个事件(ex.call到xml解析器)。那么哪个是最好的方式(在php中)来监视文件夹,并根据它的状态触发事件? Thanx!

There is a folder in which xml files are beeing copied at no particular time, when an event is happening. I want a php way to inspect the folder's status and when an xml file arrives, an event will be triggered.(ex.call to the xml parser). So which is the best way (in php) to monitor a folder and trigger events according to it's status? Thanx!

推荐答案

没有尝试过,但可能 Inotify 可以帮助您:

Haven't tried it, but maybe Inotify can help you:


inotify是一个Linux内核子系统,扩展文件系统以注意文件系统的更改,并将这些更改报告给应用程序。

inotify is a Linux kernel subsystem that acts to extend filesystems to notice changes to the filesystem, and report those changes to applications.

有一个PHP扩展名为inotify,请参阅 Inotify 文件 inotify PECL

There's a PHP extension for inotify, see InotifyDocs and inotifyPECL.

如果您在linux上运行,另一种方法是使用独立于PHP的守护进程监视目录以进行更改。您可以使用 dnotify (由inotify废弃),例如:

Another alternative if you're running on linux is to use a PHP-independent daemon to monitor a directory for changes. You can use dnotify for it (obsoleted by inotify), something like:

dnotify -a -r -b -s /path/ -e <command>;

每次修改其他文件夹中的一个文件时,它将执行该命令(-a -r -b -s =任何访问/递归目录查找/在后台运行/无输出)。

It will execute the command each time one of the files in other folder are modified (-a -r -b -s = any access/recursive directory lookup/run in background/no output).

相关:

  • Read file change in php (linux equivalent of tail -f )
  • How to efficiently monitor a directory for changes on linux?

这篇关于文件夹监视和事件触发根据php中的文件夹状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆