Hotel inventories, stock prices, order statuses, metal rates — some data goes stale in seconds. If your system syncs by calling a URL (for example sync_hotel_details.php), you may need that URL hit every 5–30 seconds. Standard cron cannot do that. Here is why, and what to do instead.
Why cron stops at one minute
A crontab entry has five time fields: minute, hour, day of month, month and day of week. The smallest unit is one minute, so * * * * * — "every minute" — is as fast as cron goes. Hosting panels such as Hostinger's hPanel or cPanel follow the same rule.
Option 1: several offset cron jobs
To run every 15 seconds you can add four cron jobs that each start every minute, three of them after a short sleep:
* * * * * curl -s https://example.com/sync.php
* * * * * sleep 15; curl -s https://example.com/sync.php
* * * * * sleep 30; curl -s https://example.com/sync.php
* * * * * sleep 45; curl -s https://example.com/sync.php
Good: simple, survives server restarts. Bad: if one request takes longer than 15 seconds, calls overlap and can run in parallel, which can double-process data.
Option 2: a long-running PHP loop (what the URL Runner does)
A single PHP process runs a loop: call the URL, wait for the response, log it, sleep for the interval, repeat. Because it waits for each response before sleeping, requests never overlap — ideal for heavy sync jobs like "download 300 hotels".
ignore_user_abort(true); // keep running if the browser closes
set_time_limit(0); // no PHP time limit
while (!file_exists($stopFile)) {
$ch = curl_init($targetUrl);
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 180]);
$body = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($code !== 200 || !$body) { sleep(15); continue; } // auto-recovery
sleep($interval);
}
Key pieces that make it reliable:
- Detach from the browser: send the response, close the connection and call
fastcgi_finish_request()where available. - A stop file: the loop checks for a
stop_process.txtfile on every pass, so you can shut it down cleanly from a dashboard. - Timeouts: a hard cURL timeout (e.g. 180 seconds) stops one hung request from freezing the loop.
- Auto-recovery: on error, wait 15 seconds and retry instead of crashing.
- Logs: write each run's timing, HTTP code and the last lines of output to a log file you can watch live.
Option 3: a proper queue or daemon
On a VPS you can run a real background worker with Supervisor or systemd, or use a queue (Redis, RabbitMQ). This is the most robust setup, but it needs root access — not something most shared hosting allows.
Check your hosting limits
Shared hosts sometimes kill PHP processes that run for hours or use too much CPU. Before relying on a background loop:
- Ask your host whether long-running PHP processes are allowed.
- Use the longest interval your data can tolerate — 10 seconds is often plenty.
- Add a slower safety cron (every 5 minutes) that alerts you or restarts the loop if the log stops updating. See cron job vs background runner.
Do it without writing code
The Cron URL Runner packages Option 2 into a dashboard: enter the target URL, pick 5, 10 or 30 seconds, click Start, and watch live logs, uptime and a countdown to the next request. It is free to use and works with any public URL.
Quick answers
Can cron run every 10 seconds?
Not directly — the smallest standard cron unit is one minute. You can chain several sleep-offset jobs, or run one long-lived loop that sleeps between requests.
Will a background PHP loop stop when I close the browser?
Not if it uses ignore_user_abort(true) and set_time_limit(0) and the host allows long-running PHP. Some shared hosts still kill long processes, so check your host's limits.