如何有效地监控linux上的更改目录? [英] How to efficiently monitor a directory for changes on linux?

查看:118
本文介绍了如何有效地监控linux上的更改目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在和Magento合作,并且有一个将CSS和Javascript合并成一个大文件的功能。



无论其利弊如何,都存在以下问题:



最终文件被缓存在多个级别,包括但不限于:




  • Amazon CloudFront

  • 代理服务器

  • 客户端浏览器缓存



Magento使用连接的css文件名的MD5和来生成新的文件名合并的css文件。所以每个具有不同的css文件集的页面都可以获得正确的合并的css文件。



为了解决缓存问题,我还将文件修改时间戳记包含在哈希,所以每次修改一个css文件时都会生成一个新的哈希值。



所以非重新验证缓存得分的全部优点,但如果某些内容发生变化,则可以立即显示,因为资源链接已更改。



到目前为止这么好:



只有问题是,用于生成的文件名只有通常是直接在HTML-Head块中引用, 包含 p>

所以在css文件中导入的文件的更改不会导致新的哈希。



不,我真的不想递归地解析所有的导入并扫描它们或类似的东西。



我宁愿考虑一个基于目录的解决方案。有没有什么可以有效地监控文件系统上的目录中的最后一次更改?



我们正在使用ext4。



或者也许有另一种方式,也许用find命令,所有的工作都是基于inode索引?



这样的东西? >

我看到很多程序可以立即查看更改,而无需扫描整个文件系统。我相信还有一些在linux下可以使用的文件操纵手表守护进程。



问题是css目录非常庞大。



任何人都可以指出我的方向正确吗?

解决方案

我建议您使用php-independent守护程序修改主要css文件的更改日期,当其中一个依赖php文件被修改。您可以使用dnotify,如:

  dnotify -a -r -b -s / path / to / imported / css / files / -e touch / path / to / main / css / file; 

每次其他文件夹中的一个文件被修改时,它将在主css文件上执行touch (-a -r -b -s =任何访问/递归目录查找/在后台运行/不输出)。或者您可以执行任何其他操作,并从PHP进行测试。


I am working with Magento, and there is a function that merges CSS and Javascript into one big file.

Regardless the pros and cons of that, there is the following problem:

The final file gets cached at multiple levels that include but are not limited to:

  • Amazon CloudFront
  • Proxy servers
  • Clients browser cache

Magento uses an MD5 sum of the concatenated css filenames to generate a new filename for the merged css file. So that every page that has a distinct set of css files gets a proper merged css file.

To work around the caching issue, I also included the file modification timestamps into that hash, so that a new hash is generated, everytime a css file is modified.

So the full advantages of non revalidative caching score, but if something gets changed, its visible instantly, because the resource link has changed.

So far so good:

Only problem is, that the filenames that are used to generate the has, are only the ones that would normally be directly referenced in the HTML-Head block, and don't include css imports inside those files.

So changes in files that are imported inside css files don't result in a new hash.

No I really don't want to recursively parse all out imports and scan them or something like that.

I rather thought about a directory based solution. Is there anything to efficiently monitor the "last change inside a directory" on a file system basis?

We are using ext4.

Or maybe is there another way, maybe with the find command, that does all the job based on inode indexes?

Something like that?

I have seen a lot of programs that instantly "see" changes without scanning whole filesystems. I believe there are also sort of "file manipulation watch" daemons available under linux.

The problem is that the css directory is pretty huge.

Can anyone point me in the right direction?

解决方案

I suggest you use php-independent daemon to modify change date of your main css file when one of dependent php files are modified. You can use dnotify for it, something like:

dnotify -a -r -b -s /path/to/imported/css/files/ -e touch /path/to/main/css/file;

It will execute 'touch' on main css file 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). Or you can do any other action and test for it from PHP.

这篇关于如何有效地监控linux上的更改目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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