Creating a PHP daemon in Apache

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
ashishga
Forum Newbie
Posts: 11
Joined: Tue Mar 28, 2006 5:02 am

Creating a PHP daemon in Apache

Post 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
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

CRON?
ashishga
Forum Newbie
Posts: 11
Joined: Tue Mar 28, 2006 5:02 am

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

cron is available on Windows too.

google icron.
ashishga
Forum Newbie
Posts: 11
Joined: Tue Mar 28, 2006 5:02 am

Post 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
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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
ashishga
Forum Newbie
Posts: 11
Joined: Tue Mar 28, 2006 5:02 am

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
ashishga
Forum Newbie
Posts: 11
Joined: Tue Mar 28, 2006 5:02 am

Post 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
Post Reply