Inspector Mills Posted June 16, 2011 Share Posted June 16, 2011 Hi there I have a strange request, and am not sure if it will be possible. I need to be able to POST XML data to a url, that will be extracted from a document. I have read up a little, and have found that both extracting data from a document, and POSTing to a url is possible in PHP. However, the problem that I have is this: I do not know how to trigger the PHP action. I am using a hotfolder-based application to generate the XML file, which places the XML document into a specific folder. I need for PHP to act on the file when it arrives in that folder, and automatically POST the data to the necessary url. In a sense, I need the folder into which the XML files are being saved, to be some kind of "hotfolder" which will be polled or "watched" by an application, and kick into action once a file arrives in that folder. The reason I mention that I am using a hotfolder-based application, is that it is possible that I create a custom hotfolder which will trigger a batch file when a file arrives in the folder that is being watched. I can make this batch file to do whatever I need to. In other words, a possible solution would be to have a batch file trigger the PHP action. Again, I do not know if this possible with a batch file, or how do do it if it is. Any guidance would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/239513-trigger-php-action-from-file-in-folder/ Share on other sites More sharing options...
dragon_sa Posted June 16, 2011 Share Posted June 16, 2011 I found this on CPAN as a possible solution for your request, there are some other alternatives for this, but this one has less overhead than some of the others. http://search.cpan.org/~mlehmann/Linux-Inotify2-1.21/Inotify2.pm Quote Link to comment https://forums.phpfreaks.com/topic/239513-trigger-php-action-from-file-in-folder/#findComment-1230370 Share on other sites More sharing options...
trq Posted June 16, 2011 Share Posted June 16, 2011 You can easily trigger php scripts from a batch file. Take a look at the clin section of the manual cli. Quote Link to comment https://forums.phpfreaks.com/topic/239513-trigger-php-action-from-file-in-folder/#findComment-1230389 Share on other sites More sharing options...
Inspector Mills Posted June 17, 2011 Author Share Posted June 17, 2011 I have since discovered that I cannot use the batch file in my third-party hotfolder, because I cannot find a way of getting the batch file to read the contents of the specific file (the XML file) that is triggering the batch action. Even if I could, I would need for PHP to read the contents or, more accurately, extract the contents of this file for POSTing. The chances are there are going to be a number of files waiting in this folder, so PHP would need to know which one to look at. Which takes me back to having a folder "polled" by another application that can trigger the PHP action. Someone suggested CRON - I will investigate this as an option. Another potential problem comes to mind, though - the file would need to be deleted once the action has been called on, otherwise it would repeat the action indefinitely. Thanks for your assistance - it is probably quite evident that I am a bit out of my depth here! Quote Link to comment https://forums.phpfreaks.com/topic/239513-trigger-php-action-from-file-in-folder/#findComment-1230945 Share on other sites More sharing options...
trq Posted June 17, 2011 Share Posted June 17, 2011 You might also want to take a look at incrond, it is different to normal cron in that it executes script when certain filesystem events occur (ie; a file is created within a certain directory), not like normal cron which just executes scheduled tasks. Quote Link to comment https://forums.phpfreaks.com/topic/239513-trigger-php-action-from-file-in-folder/#findComment-1230964 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.