• 0

[PHP] live update?


Question

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.

Link to comment
https://www.neowin.net/forum/topic/593664-php-live-update/
Share on other sites

13 answers to this question

Recommended Posts

  • 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.

  • 0
  Kudos said:

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
  • 0
  -Alex- said:
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

  • 0

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.

  • 0
  metal_dragen said:
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

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Display Driver Uninstaller (DDU) 18.1.2.3 by Razvan Serea Display Driver Uninstaller (DDU) is a utility for completely removing AMD/NVIDIA/INTEL graphics drivers and related packages from your system, attempting to eliminate all leftovers (including registry entries, folders and files, driver store). Though AMD/NVIDIA/INTEL drivers can usually be removed via the Windows Control Panel, this uninstaller tool was created for situations where standard uninstall fails, or when you need to fully remove NVIDIA or ATI graphics card drivers. After using this driver cleaner, your system will behave as though it’s the first time you’re installing a new driver—similar to a fresh Windows installation. As with all such tools, we recommend creating a restore point beforehand, allowing you to undo changes if issues arise. If you're having trouble installing an older or newer driver, try it—there are reports that it resolves such problems. Recommended usage: The tool can be used in Normal mode but for absolute stability when using DDU, Safemode is always the best. Make a backup or a system restore (but it should normally be pretty safe). It is best to exclude the DDU folder completely from any security software to avoid issues. You do NOT need to uninstall the driver prior using DDU. Requirements: .NET Framework 4.8 Compatible with Windows 7, 8, 8.1, 10, and 11 (32-bit or 64-bit) Note: Using on Insider Preview builds is at your own risk. Display Driver Uninstaller (DDU) 18.1.2.3 changelog: All GPUs: Fixed hardware rescan issue when cleaning all GPUs without restarting or shutting down UI: Added Guru3D mention in the About section. General: Various fixes and enhancements. Download: Display Driver Uninstaller (DDU) 18.1.2.3 | 1.7 MB (Freeware) Download: DDU Portable | 1.2 MB Links: Display Driver Uninstaller Home Page | Screenshot | Forum Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • That would be nice, if excel could refresh pivot tables without bugs. Frequently you refresh a pivot and all parameters get lost. Now this will happen automatically. Bravo MS!
    • If one could ever put all the crap of the world in one box, that would be Microsoft.
  • Recent Achievements

    • Week One Done
      Homayoun Hotak earned a badge
      Week One Done
    • Dedicated
      Profit earned a badge
      Dedicated
    • One Month Later
      hhgygy earned a badge
      One Month Later
    • Week One Done
      hhgygy earned a badge
      Week One Done
    • One Year In
      NIKI77 earned a badge
      One Year In
  • Popular Contributors

    1. 1
      +primortal
      645
    2. 2
      ATLien_0
      241
    3. 3
      Xenon
      168
    4. 4
      neufuse
      148
    5. 5
      +FloatingFatMan
      123
  • Tell a friend

    Love Neowin? Tell a friend!