Answer the question
In order to leave comments, you need to log in
Why does cron run three requests instead of one?
Good day. Can you please tell me why cron duplicates the record in the database 3 times in a row?
The essence of cron: Every hour, it monitors the load and sends the result to the database. Every two hours, a graph should be drawn. But cron runs the job 3 times and plots the results 3 times. Accordingly, three identical dates are displayed on the chart.
Here is the cron command (Run every hour):
0 */1 * * * screen -dmS graph_servers_hour bash -c 'cd /var/gsmanager && php cron.php kJ3odY threads graph_servers_hour'
<?php
if(!DEFINED('GSmanager'))
exit(header('Refresh: 0; URL=http://'.$_SERVER['SERVER_NAME'].'/404'));
class graph_servers_hour extends cron
{
function __construct()
{
global $sql, $start_point;
$servers = $sql->query('SELECT `id`, `online`, `ram_use`, `cpu_use`, `hdd_use`, `date` FROM `servers` ORDER BY `id` ASC');
while($server = $sql->get($servers))
{
if($server['date']+3600 > $start_point)
continue;
$sql->query('INSERT INTO `graph_hour` set `server`="'.$server['id'].'",'
.'`online`="'.$server['online'].'",'
.'`cpu`="'.$server['cpu_use'].'",'
.'`ram`="'.$server['ram_use'].'",'
.'`hdd`="'.$server['hdd_use'].'", `time`="'.$start_point.'"');
}
return NULL;
}
}
?>
Answer the question
In order to leave comments, you need to log in
0 */1 * * * screen -dmS graph_servers_hour bash -c 'cd /var/gsmanager && php cron.php kJ3odY threads graph_servers_hour'
Why are you running all this in the screen? Why some intermediate "crown tracking script"? I see opportunities for simplification in this architecture. */1
- redundant composition, just write 0 * * * *
.
0 */1
if every two hours, then more precisely:
0 */2
further:
if($server['date']+3600 > $start_point)
continue;
- most likely the out of sync also goes by the time the script is launched by cron and in the script itself, try +3601
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question