The Little Guy Posted January 19, 2010 Share Posted January 19, 2010 Is there a way for me to automatically run a php file when a file gets added to a directory, or is this impossible? Quote Link to comment https://forums.phpfreaks.com/topic/188999-run-file-automatically/ Share on other sites More sharing options...
oni-kun Posted January 19, 2010 Share Posted January 19, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/188999-run-file-automatically/#findComment-997889 Share on other sites More sharing options...
The Little Guy Posted January 19, 2010 Author Share Posted January 19, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/188999-run-file-automatically/#findComment-997890 Share on other sites More sharing options...
oni-kun Posted January 19, 2010 Share Posted January 19, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/188999-run-file-automatically/#findComment-997891 Share on other sites More sharing options...
The Little Guy Posted January 19, 2010 Author Share Posted January 19, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/188999-run-file-automatically/#findComment-997896 Share on other sites More sharing options...
oni-kun Posted January 19, 2010 Share Posted January 19, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/188999-run-file-automatically/#findComment-997900 Share on other sites More sharing options...
The Little Guy Posted January 19, 2010 Author Share Posted January 19, 2010 Ill check it out, I have tried piping, but I haven't gotten anything to work yet. here is what I have tried (.procmailrc): MAILDIR=$HOME/Maildir SHELL=/bin/sh :0 * ^Subject:.* | /home/brainsearch/scripts/test.php Quote Link to comment https://forums.phpfreaks.com/topic/188999-run-file-automatically/#findComment-997904 Share on other sites More sharing options...
Daniel0 Posted January 19, 2010 Share Posted January 19, 2010 Use Subversion and post-commit hook. Quote Link to comment https://forums.phpfreaks.com/topic/188999-run-file-automatically/#findComment-997947 Share on other sites More sharing options...
salathe Posted January 19, 2010 Share Posted January 19, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/188999-run-file-automatically/#findComment-997982 Share on other sites More sharing options...
The Little Guy Posted January 20, 2010 Author Share Posted January 20, 2010 I GOT IT!!! I had my .forward.postfix file in the wrong directory! I guess it had to be in my users root, not my wesites root! Quote Link to comment https://forums.phpfreaks.com/topic/188999-run-file-automatically/#findComment-998439 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.