Creating a PHP daemon in Apache
Moderator: General Moderators
Creating a PHP daemon in Apache
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
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
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
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
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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.
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.