Good day.

My question is, is it possible to create a task for CRON directly from PHP? That is, it would be desirable if, during the execution of a script, a task was set up, which will be completed in 3 days.

I still have one option - to put CRON for each day, which will check for new tasks and, if found, perform them. But this is an extra job CRON, in fact. And I would like to create only the necessary tasks, but at the same time that the script itself created them.

  • Yes, and I want to add that it is not always in 3 days, always in different ways (but precisely in days), while the first script can be executed at any time, but it is necessary that the second script be executed exactly N * 24 hours. - Shevsky
  • Plus, in my version there will be discrepancies in time, in a day - too much, and if you check every hour too much is loaded. - Shevsky

1 answer 1

Working directly with the crown through PCP is not recommended (and I don’t even know if it is possible).

The best option, in my opinion, is as follows:

1) Create a database and a table in which your tasks will be stored (if necessary, another table or file in which there will be an execution log).

2) Write a pkhp script that will check this table and execute scripts whose time has come, but it’s not worth checking.

3) Add a task in crown to run this script, for example, every hour (yes, at least every 10 minutes or a minute).

In this case, you will have every opportunity to complete the work and establish a schedule.

In theory, there is not enough point 4 here - to make an API for working with your system (adding / changing / deleting tasks, getting a list of tasks, etc.).

PS Here I found the material on working with the crown directly from the PCP. There are still various ways through which you can directly change the file / etc / crontab, but IMHO is a bad style to give access to the user php to work directly with cron.

  • Well, I did just that. But I do not keep it in the database, I don’t want to contact it once more, I keep the tasks in the file, it seems, it should work faster, and the load should be minimized. But not every hour, but every 12 hours. What a pity that in 2016 it is impossible to do this normally. - Shevsky