Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
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 ...
  1. #1
    Just 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.

  2. #2
    Linux 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

  3. #3
    Just 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?

  4. #4
    Linux Enthusiast Kloschüssel's Avatar
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    717
    That problem can be worked around with pid files that behave as locks.

    the steps in the cron script would be:
    Code:
    # if pid file exists, terminate
    # create pid file
    # execute
    # remove pid file
    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.

  5. #5
    Just 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?

  6. #6
    Just 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.

  7. #7
    Just 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?

  8. #8
    Linux Enthusiast Kloschüssel's Avatar
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    717
    So how will the file be? First I write the php file is it? Then wat is next?
    Don't know how cent os does it, I'm a child of the debian world. If it has lsb installed, the code may be somewhere around /lib/lsb/init-functions.

    What do you think?
    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.

    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.

  9. #9
    Just 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.

  10. #10
    Linux Enthusiast Kloschüssel's Avatar
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    717
    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.

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...