Results 1 to 4 of 4

Thread: Execute a cron job from PHP

  1. #1
    Join Date
    Jul 2007
    Posts
    5

    Default Execute a cron job from PHP

    I have a question...this actually a little backward from what most people want.

    I want to have a PHP script trigger a Cron job(PHP DB backup script) to execute when certain DB changes take place. The reason I want it to occur like this is, I want this process to occur in the background and not affect the user as DB dumps may cause the browser to time out.

    I have a cron job set to automatically execute a PHP script daily to backup/replace a mysql dump file, I want to be able to execute this cron programmatically from the site.

    Anyone ever do this or is it even possible? Thanks in advance for any insight.
    Frank

  2. #2
    Join Date
    Feb 2009
    Posts
    4

    Default

    You'd actually need to have the cron job run a php script that checks your database size and saves the size so that the next time the script is run you can compare the two sizes for differences. Then if there is a difference in the size, you'd just run the script you want to run for when changes have been made to your database. This page might help you get started on checking the DB size.

    http://www.drquincy.com/blog/get-the...base-with-php/
    Last edited by farcaster; 05-31-2011 at 07:35 AM. Reason: released from moderation

  3. #3
    Join Date
    May 2011
    Posts
    9

    Default

    Hmm, the cron job has a set schedule so it would be difficult to tell it to run only when database changes are made. What "certain DB changes" are you trying to monitor? There's probably an easier way to do it, let us know.

  4. #4
    Join Date
    Nov 2006
    Location
    Sydney, Australia
    Posts
    4,944

    Default

    The simplest way is to have the PHP script update a flag or flags that the cron job can test to see what if anything it needs to do this time.

Tags for this Thread

Posting Permissions

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