Results 1 to 10 of 15
Dear All,
I have an application where from time to time I need to check the db for some value and run some functions to do some checks. What is ...
- 05-15-2011 #1Just Joined!
- Join Date
- Jul 2010
- Posts
- 64
Php daemon vs Cron Job
Dear All,
I have an application where from time to time I need to check the db for some value and run some functions to do some checks. What is the best option do it as php daemon or cron job?What I worried of cron job is the overalapping.
- 05-15-2011 #2Linux Newbie
- Join Date
- Apr 2010
- Location
- Novosibirsk, Russia
- Posts
- 136
You can just write a php script that does the work, and run it under cron. I think this is a good and easy way
- 05-16-2011 #3Just Joined!
- Join Date
- Jul 2010
- Posts
- 64
Dear Schmidt,
I am worried just that if via cron if might overlap. Say the script is running now and took more than one minute and the second minute the other instance of it is running ready? How you guys solve this?
- 05-16-2011 #4
That problem can be worked around with pid files that behave as locks.
the steps in the cron script would be:
Those things / functions may be already written down in some shared startup-scripts. So you wouldn't have to reinvent the wheel, but rather just source the right files. Which files depends on the distribution / version of distri you're running.Code:# if pid file exists, terminate # create pid file # execute # remove pid file
- 05-16-2011 #5Just Joined!
- Join Date
- Jul 2010
- Posts
- 64
Dear Kloschussel,
Say I am using centos 5.5. So how will the file be? First I write the php file is it? Then wat is next?
- 05-17-2011 #6Just Joined!
- Join Date
- Apr 2011
- Posts
- 19
My 2 cents
If you are really testing every 60 seconds, I would go with the daemon, unless the process is large. Keeping around a daemon may be less load than starting a process that frequently. Usually when I think of cron jobs, I think daily or hourly.
- 05-17-2011 #7Just Joined!
- Join Date
- Jul 2010
- Posts
- 64
Dear Tabie,
When you say daemon here is cron job right just to make sure the right terminology. The thing is like in the backend I have huge number of data coming via gps. So I just store them into database so every minute I thought I will check and process those new data. What do you think?
- 05-17-2011 #8Don't know how cent os does it, I'm a child of the debian world.So how will the file be? First I write the php file is it? Then wat is next?
If it has lsb installed, the code may be somewhere around /lib/lsb/init-functions.
I think that a cron-job can of course do whatever one needs and it can indeed be triggered every minute. If or if not a php script can handle the load is another story that can be discussed reasonably only if a major insight into the usecase is given. And as long one does not spawn processes that eat up each others resources, it should be fine.What do you think?
EDIT: I've got in the back of my brains a project named "supercron". Maybe they implemented the singleton requirement. Good luck!Last edited by Kloschüssel; 05-17-2011 at 12:53 PM.
- 05-17-2011 #9Just Joined!
- Join Date
- Jul 2010
- Posts
- 64
Dear Kloschussel,
So based on your experience better to go with cron rather than php_daemon. So never mind about the centos let me do some findings on it. Thank you.
- 05-17-2011 #10
I just read up what this php_daemon is - I kind of misunderstood it and thought of it as you would want a cron job to trigger a website (wget) which executes the php script. What I've read just now about php_daemon looks quite good.
For completeness, I would like to note that there is also the java equivalent for cron named quartz.
Summarizing the technologies gives:
- cron
- supercron
- quartz (run by init.d)
- quartz (run by tomcat as a service)
- php_daemon
Maybe you could give all technologies a shot, compare the outcome and let us know what you learned from it?
I am sure a lot of people in this world could find it useful to have a comparison with pro and cons over one technology. Of course each technology is praised by his inventor and therefore I was unable to find an objective opinion.


Reply With Quote