1

Are there any simple ways to run a PHP script when a file is added to a specific directory?

On linux there are perfect tools for this like inotify/dnotify, can't find any for Windows.

If I run a PHP script that loops infinitely - will that make a significant impact on cpu performance (if all it does is check folder for contents)?

I read that Win32::ChangeNotify could be used, but I'm a noob in Perl, so I have no idea how to set it up.

1 Answer 1

1

The easiest way to manage this would be to create a cron job that runs your script every minute (or however often you wish to check).

Edit - Just read the post again, and it hit me that you're using Windows. I suppose you can use Scheduled Tasks to do this.

Sign up to request clarification or add additional context in comments.

3 Comments

Use of cron for such tasks (or whatever scheduling mechanism Windows gives) is both ugly and rather inefficient. Because a) you are periodically (and frequently) burning cycles for nothing -- there are no files to process most of the time; b) when the files do appear, the delay in their processing is, on average, one half of the cron-job's period. The right way is finding the mechanism the asker is seeking -- the program starts and is initialized, asks the OS to notify it of certain events and goes to sleep (and can be paged-out), until woken up by the kernel.
@MikhailT. Your comment makes sense, but that seems like it would be difficult to implement, are there command-line utilities for that?
@Artur, sorry, I'm not a Windows man. But there are cross-platform event-libraries (libevent, libev), which may have been ported to Windows already. For more, ask a question :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.