[请益] 不好意思我有一个关于php的问题

楼主: RayShigeno (RayShigeno)   2016-01-15 16:02:04
各位好
关于这个类别
class Crontab {
// In this class, array instead of string would be the standard input /
output format.
// Legacy way to add a job:
// $output = shell_exec('(crontab -l; echo "'.$job.'") | crontab -');
static private function stringToArray($jobs = '') {
$array = explode("\r\n", trim($jobs)); // trim() gets rid of the last
\r\n
foreach ($array as $key => $item) {
if ($item == '') {
unset($array[$key]);
}
}
return $array;
}
static private function arrayToString($jobs = array()) {
$string = implode("\r\n", $jobs);
return $string;
}
static public function getJobs() {
$output = shell_exec('crontab -l');
return self::stringToArray($output);
}
static public function saveJobs($jobs = array()) {
$output = shell_exec('echo "'.self::arrayToString($jobs).'" | crontab
-');
return $output;
}
static public function doesJobExist($job = '') {
$jobs = self::getJobs();
if (in_array($job, $jobs)) {
return true;
} else {
return false;
}
}
static public function addJob($job = '') {
if (self::doesJobExist($job)) {
return false;
} else {
$jobs = self::getJobs();
$jobs[] = $job;
return self::saveJobs($jobs);
}
}
static public function removeJob($job = '') {
if (self::doesJobExist($job)) {
$jobs = self::getJobs();
unset($jobs[array_search($job, $jobs)]);
return self::saveJobs($jobs);
} else {
return false;
}
}
}
在这边附上网址
http://www.kavoir.com/2011/10/php-crontab-class-to-add-and-remove-cron-jobs.html
因为完全没学过php
但目前需要用到
想问各位
如果我想要增加一个例如: 30 14 * * * sudo python timeopen.py这个任务
我在php网页需要打什么code啊QQ
作者: MOONRAKER (㊣牛鹤鳗毛人)   2016-01-15 18:08:00
阿里面不是一直在呼唤Jobs 这么爱Jobs你就照着呼一下阿

Links booklink

Contact Us: admin [ a t ] ucptt.com