DEV Community

gyudoza
gyudoza

Posted on

4 3

php cron manager for managing linux's cronjob

I managed it for inidividual use only but i think someone need it. When i use linux crontab i felt very uncomfortable unlike iptables, so i meade it as a php code instead of shell script. sorry I've no skills about shell script.

Whatever I tried to make this as simplest. So There's no handling about some danger commands(e.g : rm -rf [somethings], halt, reboot, shutdown, and so on... ). So I want you to be careful when you use this class. I've no responsibility about problems occurred by using this class. And understandably you need to know about cron commands.

Cronjobs are made by this class, managed by CRONTAG. CRONTAG is a comment that pasted cronjob's tail. It creates and removes about cronjobs by using regex,.

code and manual are below repo. i don't know how to write code snipet in here. Please use it well.

PHPCronManager

Preface

I tried to make this as simplest. So There's no handling about some danger commands(e.g : rm -rf [somethings], halt, reboot, shutdown, and so on... ) So I want you to be careful when you use this class. I've no responsibility about problems occurred by using this class.

Description

Be made to approach linux's cron system. Cronjobs are made by this class, managed by CRONTAG. CRONTAG is a comment that pasted cronjob's tail.

Test Environment

OS : CentOS 6.8 (Final)
php : PHP 7.0.16
And understandably crond installed.

Update Note

  • v1.01(2018-12-20)
    • function add_cronjob's command changed more safety.
  • v1.00(2018-11-10)
    • uploaded

e.g (assume u to load this file completely)

$cron_manager = new CronManager()
$cron_add_result = $cron_manager->add_cronjob('* * * * * date >> /var/testdir/datelog.txt 2>&1', 'datelog');
//if this codes worked normally, u will get array return with
Enter fullscreen mode Exit fullscreen mode

Image of Datadog

Master Mobile Monitoring for iOS Apps

Monitor your app’s health with real-time insights into crash-free rates, start times, and more. Optimize performance and prevent user churn by addressing critical issues like app hangs, and ANRs. Learn how to keep your iOS app running smoothly across all devices by downloading this eBook.

Get The eBook

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs