
How to run cronjob on Windows localhost without Windows Scheduler

Every once in a while, a web developer encounters a situation where a page needs to be refreshed to load the latest data from a MySQL database. This could happen for several reasons:
API request limits
Limited permissions on a development machine or server
Avoiding complex scheduling setups like Windows Task Scheduler
Whatever the reason, a simple solution is to refresh the page automatically using JavaScript. This approach is lightweight, requires no additional libraries, and works in any programming environment.
Automatic Page Refresh with JavaScript
You can include the following script at the end of your cronjob page or development page. Once you run the page through your browser, leave the tab open, and it will refresh at the interval you set:
<script>
(function() {
// Your page initialization code here
// The DOM will be fully available
setTimeout(function() {
window.location.reload(); // Refreshes the page
}, 5 * 60 * 1000); // Refresh every 5 minutes
})();
</script>
How it works:
The script uses a self-executing function to ensure it runs immediately after the page loads.
setTimeouttriggers a reload after a specified time (in this case, 5 minutes).No external libraries are required. You can embed this in any HTML page or dynamic web page generated by PHP, Node.js, Python, etc.
This method is perfect for quick updates, lightweight cron-like behavior, or testing scenarios without relying on system schedulers.
Handling Pagination When Refreshing
Another common challenge is ensuring that the page refresh doesnβt repeatedly reload the same records. To update newer records with every refresh, pagination needs to be handled. There are two common approaches:
Sessions
The current page number or record pointer is stored in the session.
Issue: If the server or browser session expires, your pagination state resets.
Cookies (Recommended)
Store the pagination state in a cookie with a long expiry date.
This keeps your pointer intact even after closing the browser or restarting the machine.
Example of using a cookie for pagination:
// Get the current page from the cookie
function getCurrentPage() {
return parseInt(document.cookie.replace(/(?:(?:^|.*;\s*)page\s*\=\s*([^;]*).*$)|^.*$/, "$1")) || 1;
}
// Set the next page in the cookie
function setNextPage(page) {
document.cookie = "page=" + page + "; path=/; max-age=" + 60*60*24*30; // 30 days expiry
}
(function() {
let page = getCurrentPage();
// Load content for the current page
console.log("Loading page:", page);
// Update cookie for the next refresh
setNextPage(page + 1);
// Refresh the page after 5 minutes
setTimeout(function() {
window.location.reload();
}, 5 * 60 * 1000);
})();
Benefits of using cookies:
Pagination state persists even if the session expires.
Ideal for development or data-fetching scripts that need to continuously process records.
Conclusion
Automatically refreshing a web page using JavaScript is a simple and effective solution for updating MySQL data without complicated cron jobs or schedulers. Combining this approach with cookies for pagination ensures that you can traverse new records efficiently without losing your place.
This method is lightweight, flexible, and can be implemented in any language or environment that serves HTML pages.
Tags: cronjob, localhost, MySQL database
