简体   繁体   中英

Run PHP page every hour automatically-without using Cron jobs

How can i run or refresh PHP page every 10 Minutes or an hour. so that add new record from one database to another i doesn't matter with using javascript but without using cron jobs .

You can depend on the traffic to your website if it's frequent enough. Drupal has something called poor man's cron. Basically you store the date-time that the cron job was last run. Each time a user visits a page on your website, you fetch the date-time, compare it with the current date-time to see if you need to run the cron job (in your case, see if an hour has passed). If the required amount of time has passed, then run your cron job, and store a new date-time. If your required amount of time hasn't passed, then do nothing.

This approach has a few caveats.

  • You really should be using cron, and not doing this. There's a reason it's called poor man's cron. If you're using some hosting service by someone else, their technical support should be able to help you setup a cron job. If the service has cPanel you can do it from cPanel. https://documentation.cpanel.net/display/ALD/Cron+Jobs
  • You are completely dependent on website traffic to trigger your cron job. You need to decide if it's OKay for your cron job to not be run for a period of time where users are not visiting your website.
  • You're slowing every request to your website down by a fetch to whatever persistent store is holding the last date-time the cron job was run.

with javascript you can use the setTimeout() function but the user will need to keep the page opened.

ie

setTimeout(function(){ your_process(); }, 360000); // every hour

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM