Jump to content
philaj

Poll Folders for new File

Recommended Posts

Hi All - hope someone has done this before.

I need to create a PHP script that detects the presence of a new file appearing into a folder, and process it.

This HAS to be supported by Windows IIS  (Have looked at FAM for Linux but can't use it).

I could do a loop with some sleep that checks the directory every x seconds - but this has been discounted by the client as either a) too resource hungry or b) not quick enough if there is a delay.

Add ons, extensions or even external 3rd party tools would all be acceptable.

Any ideas?

Phil

Share this post


Link to post
Share on other sites

How do these files actually "appear" in your system? Can you not be alerted to a new upload before or as it happens?

Share this post


Link to post
Share on other sites

Hypothetically you could use the COM/DOTNET extension and use .NET's FileSystemWatcher.

Share this post


Link to post
Share on other sites

 

ginerjm - The files are ftp'd into a location - and my script needs to process them. 

Thanks requinix I'll check that out

Share this post


Link to post
Share on other sites
On 6/4/2019 at 10:50 AM, philaj said:

I need to create a PHP script that detects the presence of a new file appearing into a folder, and process it.

This HAS to be supported by Windows IIS

IIS implements a Request-Response model.  It's not suited to long-running or cyclical processes.

However, PHP code doesn't only run inside IIS.  You can run it as a standalone program by "feeding" the PHP script file into the PHP executable.

php.exe -f myscript.php

That means that you can create a PHP script that does whatever you want it to, and schedule it to run whenever you need it to run using, say, Windows Task Scheduler.

 

Share this post


Link to post
Share on other sites

It's a kludge, but you could always keep a list of files in a database or flatfile and schedule a CRON to run a script that scans the directory for file names, then compare that to the saved list. You'd know if something had been added or removed, though it wouldn't be instant.

Share this post


Link to post
Share on other sites

This FTP process.  Could you possibly have an influence on those doing those transfers to use a script that you provide that would not only send you the file but send a message to a script that monitors an email address of yours and follows up by doing your processing?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.