Jump to content

Run file automatically


The Little Guy

Recommended Posts

Is there a way for me to automatically run a php file when a file gets added to a directory, or is this impossible?

 

Do you mean added not via PHP (SSH/FTP/Shell)? You must run a CRON job to check, you can run it every 5 minutes for example (non-resource exhausting), the php script can check(glob) for a newly added file (adding each new one to a DB/flatfile or whatnot, or comparing unix timestamps of creation) and run another php script based off if there is a new result.

Link to comment
Share on other sites

Do you mean added not via PHP (SSH/FTP/Shell)?

 

What I was hoping I could do is the following:

 

- A file gets added to a directory

- Some sort of file senses this

- The file tells a php file to run

- The php file starts up and reads the new file in the the directory

 

I was hoping I could do something other than cron, because I want this to happen as soon as the file exists in the directory, not have a cron run every xx minutes.

Link to comment
Share on other sites

Do you mean added not via PHP (SSH/FTP/Shell)?

 

What I was hoping I could do is the following:

 

- A file gets added to a directory

- Some sort of file senses this

- The file tells a php file to run

- The php file starts up and reads the new file in the the directory

 

I was hoping I could do something other than cron, because I want this to happen as soon as the file exists in the directory, not have a cron run every xx minutes.

 

This is impossible unless you run a program on serverside (out of PHP completely) to scandir and execute php on discovery, FTP discovery is another solution but it's just not such a viable solution, A cron tab could be run xx seconds if need be, as it only executes a (should-be) short script.

Link to comment
Share on other sites

basically I am forwarding email to a folder, I then want to parse the email and save it to the database...

 

I am on a shared host, and I have no Idea how fast the script will take to parse an email.

 

You can look at this. Some mail providers allow piping, but this assumes you have shell access really, It's just not so viable to be able to do this on a shared hosting account.

Link to comment
Share on other sites

There is a PECL extension (it used to be in the PHP core) for monitoring files and directories but from the sounds of things your approach hardly seems ideal. Why can't you pipe the email directly to the PHP script which saves the message to the database?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.