First, we need to reach the following consensus:
/DEV/SHM is the memory directory under Linux, obviously in this directory is built in memory, the default can use 50% of memory, when the memory is low, you can switch to disk by swap.
INotify is the file system event monitoring under Linux, which can meet various file monitoring needs, provides interfaces such as Inotify_init,inotify_read, requires linux2.6 or more cores (uname-a view), It seems that Cygwin can't be realized.
PHP does not provide support for inotify extensions by default, so we need to download the build installation via PECL.
Download inotify (http://pecl.php.net/package/inotify), Unzip and install:
TAR-XVF INOTIFY-0.1.6.TGZCD inotify-0.1.6/usr/local/php/bin/phpize./configure--with-php-config=/usr/local/php/ Bin/php-configmake && make Install
Then load inotify.so in the php.ini file to see if there is a successful load that can be viewed through Php-i|grep inotify.
Then in the/DEV/SHM to establish the memory directory, because the queue processing is a high speed, put to disk will have a certain amount of I/O time consumption, we build/dev/shm/inotify directory, and then use PHP to write a dead loop demo to monitor the directory, in addition, by changing the/dev/ Shm/inotify the file or property of the directory to see the results:
!--? php$notify = Inotify_init (); $rs = Inotify_add_watch ($notify, '/dev/shm/ INotify ', in_create);//in_create indicates that only the creation of new files is monitored, and the specific parameter list can be found at the inotify of the manual. if (! $rs) {die (' fail to Watch/dev/shm/inotify ');} while (1) {$files = Inotify_read ($notify); Print_r ($files); Echo ' Continue to process next event ';} Using the INotify module is more flexible and resource-saving than looping and the scan directory continuously, and at Inotify_read, it is blocked until no events are received, so there is no operation where there is no action required to loop execution.
Attempts to create a new Test.txt file in/dev/shm/inotify, which returns an array of all the files in Inotify_read, such as:
array ([0] = = Array ([WD] = 1 [Mask] = 25 6 [Cookie] = 0 [name] + test.txt))