• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

  • 0
Sign in to follow this  

[PHP] live update?

Question

Andrew Lyle    336

I had an idea that the system database would updates itself at a specific time.. say January 1, 1008, at 12:01am, and send out an email or, update the entire database, and remove all dates from 2007.

Is it possible for the server to actually update itself using PHP and Mysql, without having human interactions on the page?

My real idea is to prune every day 7 days back, every day. So at 12:01, it would remove last weeks entry for this posting, and only keep 7 days history.

Share this post


Link to post
Share on other sites

13 answers to this question

Recommended Posts

  • 0
samg    2

cron jobs in your cpanel...

Share this post


Link to post
Share on other sites
  • 0
Andrew Lyle    336

I don't have cpanel.. my company uses something called H-Sphere

Share this post


Link to post
Share on other sites
  • 0
Andrew Lyle    336

Is there no active script that can do this. All I see on that web site is a url you can enter that will update at that time

my server is running off of Linux

Share this post


Link to post
Share on other sites
  • 0
generalt    0

I've been looking for a script like this as well, but I have not found a way to do it...

Share this post


Link to post
Share on other sites
  • 0
generalt    0

oh i think *nix uses cron tabs

Share this post


Link to post
Share on other sites
  • 0
sbohan    0

Maybe a little explanation as to what a cron job is would help :).

Basically and I am no authority on cron jobs at all! They are system calls that you can schedule to be performed at a set recurring time, be it minutes, hours, days etc... In your case you will want to create a script on your website that performs the database queries you require to be run and write it so it executes at run time with no need for conditionals or user interaction.

<?
mysql_query("DELETE FROM `table1` WHERE `date`<='$last_week'",dbcnx());
?>

Something as basic as that would suffice. Then once the script is completed and working, i.e when you visit said script through a web browser and then check your database all information (that you wanted to) has been successfully removed. Once this is complete set up a cron job using the link provided or even on your own server where possible that looks something like:

01 12 * * * lynx http://www.link.to/script.php

The cron job will then be ran everyday at 12:01 until it is removed from the crontab, for more information on cron jobs in general try here.

Share this post


Link to post
Share on other sites
  • 0
Andrew Lyle    336

I'm trying to run it off my own server, without the help of an off site service

or am I not understanding this at all?

some of this stuff requires me to edit folders I don't have access to on my server.. So maybe I better think of a different solution

Edited by lylesback2

Share this post


Link to post
Share on other sites
  • 0
-Alex-    101

The post above you briefly explains how to achieve this without an 'off-site service'. Cron FTW :)

Share this post


Link to post
Share on other sites
  • 0
Andrew Lyle    336
The post above you briefly explains how to achieve this without an 'off-site service'. Cron FTW :)

but that requires editing files within linux files itself... something I can't access within H-Sphere...

I know how to briefly use Ubuntu, and some of the commands, but I don't see how I can access these folders

root@pingu # cat /etc/crontab

Share this post


Link to post
Share on other sites
  • 0
metal_dragen    30

If you don't want to use an off-site service and don't have access to cron on your server, then the only way you can do this relies on either you or a visitor to the site hitting a page to trigger it.

Brief overview: write your script to perform the operations you want -> create a text file that holds a start date -> include a check on some page (index or something) to check the date in the file against the current date -> if it's whatever your range is ( >7 days or whatever), call the script that performs your operations and then write a new date to the file.

This is the only way I know of that will do this without cron or an off-site cron service (which essentially does the same thing as I outlined above, but can hit the script on an exact schedule). This method is imprecise as it relies on someone hitting the page to trigger the script which, depending on how many visitors your site has, can delay it significantly.

Share this post


Link to post
Share on other sites
  • 0
Andrew Lyle    336
If you don't want to use an off-site service and don't have access to cron on your server, then the only way you can do this relies on either you or a visitor to the site hitting a page to trigger it.

Brief overview: write your script to perform the operations you want -> create a text file that holds a start date -> include a check on some page (index or something) to check the date in the file against the current date -> if it's whatever your range is ( >7 days or whatever), call the script that performs your operations and then write a new date to the file.

This is the only way I know of that will do this without cron or an off-site cron service (which essentially does the same thing as I outlined above, but can hit the script on an exact schedule). This method is imprecise as it relies on someone hitting the page to trigger the script which, depending on how many visitors your site has, can delay it significantly.

thats not a bad idea. Just use an if statement to trigger the event, run the removal once, and write another date to the file.

I was hoping to use this live update idea, since it could come in handy in the future, but that will need to wait another time

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.