M
M
Madion2014-11-24 13:30:49
PHP
Madion, 2014-11-24 13:30:49

How to modify cron job with php?

There is a job in cron. You need to somehow change the frequency of this task using php. How to do it?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ilya Plotnikov, 2014-11-24
@ilyaplot

Run the php file every minute, and inside this script, already determine whether it is time for it to run. Get the most correct and safe option.

A
Armenian Radio, 2014-11-24
@gbg

Edit /etc/crontab.
From a security point of view, it's a huge hole to give PHP access to this file.

S
Sergey Senkevich, 2014-11-24
@ssenkevich

//получаем список работ для пользователя user
$currentJobs = shell_exec("crontab -u user -l");
//вносим нужные изменения в расписание работ
...
//сохраняем все во временном файле
$filename = tempnam(sys_get_temp_dir(), 'crontab');
file_put_contents($filename, $currentJobs);
//обновляем cron
exec("crontab -u user " . $filename);

Just keep in mind that the user from which this PHP script is run must have rights to edit the cron user user.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question