DiigIT | IT Community
No Profile Image
Welcome Guest
New User? Register | Login

Automatically update

By: rekha singh | 28 Mar 2010 3:06 pm

I'm looking for a way to modified an update php script and to set it in a way to automatically update my database every 2 hours, can any one help or advice?

Comments

Sounds like you want a script that will wait for 2 hours, then start work again. That is wrong.

Write a simple script to update the database, then close. As usual.

Use CRON to make it re-run every 2 hours.

By: rekha singh | 28 Mar 2010

There are a couple of ways to do this:

1) The first is to use a scheduled program executor like cronjobs (in Linux) and scheduled tasks (in Windows). These utilities execute a given file at set intervals or at pre-programmed dates and times.

 
Though written for cpanel users, I found this tutorial helpful understanding how to use cronjobs with php scripts:
 

http://www.trap17. com/index. php/cron- jobs-cron- jobs-cpanel_ t6321.html

I typically use a single script that runs at set intervals that checks the database for tasks that are due to be executed, rather than having a lot of entries in cronjob. I chose this method because I can give a client control
over which 'jobs' execute and when by changing parameters on a form which then changes the parameters in the database.

2) In some cases, where appropriate, and with later versions of MySQL,'events' can be created in MySQL and MySQL will execute these events automatically. Events are similar in their construction to other stored procedures. Events are associated with a single table. This works very well for deleting expired sessions or cleaning up old unused records. It may not be useful is complex processing is needed to do table updates.

Here are some links to learn how to write events:

http://dev.mysql. com/tech- resources/ articles/ mysql-events. html
http://www.phpied. com/mysql- events/

I believe it is usually better to have MySQL do the work than to have a PHP script running for server load and speed.
 
I hope this helps.

 

By: rekha singh | 28 Mar 2010

Leave a comment

Enter the text in the image
img
Can't read?
Type the characters you see in the picture below.


Close Move