开发者

PHP generate a crontab

I want to have a web interfac开发者_如何学Ce to control when to call a PHP script. In this interface I want to be able to set certain times or ranges that a script will be called. This information will be stored in a DB. When I hit save I want to have it read all the scheduled times from the DB, then format it and write it to a crontab for a cron job. Is there a way to have PHP modify a crontab file?


I would go for creating a "cron_runner.php" script that runs every minute, reads the cron data and runs them accordingly. It feels like reinventing the wheel but at least you have no problems with the file permissions.


It should be possible, but you need PHP to have the necessary rights to access the user's crontab or to execute "crontab" from the command line. In a shared hosting environment this is mostly not the case.


Actually, you can manipulate the cron jobs as simple as text files. You have to be careful not to brake anything tho.

The cron daemon saves the cronjobs for each user using the following structure:

/var
   /spool
        /cron
            /crontabs
                /root
                /user1
                /user2
                ..
                /user5

Using this information, you can modify the text file corresponding the user for which you would like to set the new cron.

Be aware that modifying system files can be dangerous and you should be extremely careful. Your application will also need some additional privileges for modifying these files.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜