Add / Remove cron work using PHP

Here is my situation: we have a third-party provider that will push XML files to our server every 30 seconds at the specified time per week. This time will change every week. Therefore, I would like to provide my users with an interface on the management side of our site, where they can “click a button” and start data capture. (and in the same way you can turn off the work)

I planned to do this using PHP. I assume that I will need to run some system commands from my script in order to schedule and delete cron jobs.

My question is: is this the best way to do this? Is there any danger when scheduling and deleting cron jobs from php? What do I need to keep in mind when I create this?

In addition, any pointers / hints on how to do this are more than welcome. Thank you in advance.

+3
source share
4 answers

I would recommend just saving the cron job, which searches for uploaded XML files that work all the time, every minute. Checking for any files in a directory is not a costly operation, for which you need to use the administrative interface to disable it when it is not needed.

+4
source

, cron PHP. () cron , PHP . , , .

+2

crontab / , script. , crontab , .

cron. / - , cronned script , , - .

cron , .

cron, .

+1
source

I used to do this. I do not recommend turning cron on / off at the crontab level.

Instead, leave cron all the time, but the PHP script should look like this:

if( ScriptIsEnabled() )
{
  DoWork()
}

ScriptIsEnabled()should look for a flag in the configuration file, database, memcache or how you want to communicate with the script. I prefer memcache (the least overhead is to just set the value) over the database.

Then you can use web gui with on / off button.

+1
source

Source: https://habr.com/ru/post/1716316/


All Articles