Page 1 of 1
Creating a PHP daemon in Apache
Posted: Tue Mar 28, 2006 5:13 am
by ashishga
Hi All,
I have created a PHP script that reads a directory, and lists down the files in the directory and then after performing certain operations, it deletes those files.
Now, the files in the directory our created from separate logic, say a user on the web page creates a file in it.
My PHP script has to detect any new file arrival and then automatically start working on it (which it is doing when invoked normally).
My main question is "How to allow Apache to invoke this script, when some event occurs?"
I don't want to include a infinite while loop in the script, I want the server to do that.
Please help..
Regards,
Ashish
Posted: Tue Mar 28, 2006 7:10 am
by Benjamin
CRON?
Posted: Tue Mar 28, 2006 9:27 pm
by ashishga
Hi,
I think CRON is a program that runs in UNIX, but my Apache is installed on a Windows machine.
Please provide me a Windows solution.
Regards,
Ashish
Posted: Tue Mar 28, 2006 9:44 pm
by feyd
cron is available on Windows too.
google icron.
Posted: Tue Mar 28, 2006 9:48 pm
by ashishga
Hi,
Thanks for the reply...
Can you tell me how can I make my PHP script a daemon through this, or how can I ask Icron to call my PHP script on my Apache server, whenver there is a file in the directory.
Regards,
Ashish
Posted: Tue Mar 28, 2006 10:14 pm
by josh
You'd have your script check for the existence of a file every few seconds, not a true daemon but it gets the job done
Posted: Tue Mar 28, 2006 10:24 pm
by ashishga
Hi,
What I understand from your reply is that, I need to program my script in such a way that it checks for the existence of a file in every few seconds. That means I need to implement the infinite while loop in my script, but I don't want to do that ( from within the script).
I want the server to do this job, of calling my script in every few seconds.
If there is any option in that respect, please provide me that.
If I have misinterpreted your reply, please clarify it to me.
Regards,
Ashish
Posted: Tue Mar 28, 2006 10:36 pm
by feyd
Calling it that often is up to how you set icron. Since the syntax only goes down to minutes in resolution, you'll need your script to sit and watch the directory for only a minute.
Mark the time when the script starts.
Start your infinite loop
Check the directory, process if necessary.
Sleep for however long.
Check if the current time is ~60 seconds beyond the originally marked time. When it is, break out of the loop and clean up.
Posted: Tue Mar 28, 2006 10:40 pm
by ashishga
Hi,
Thanks for all these valuable comments. I would certainly try this out and will come back to you people.
If there are more ways of doing this, please keep posting it on this thread.
Thanks and Regards,
Ashish