private function addCronJob($startDate) { $cronDate = $this->cronDateTime($startDate); $cron = new Crontab('nymedia_crontab'); $cron->addApplicationJob('yiiccmd', 'Nymedia holiday', array(), $cronDate['minute'], $cronDate['hour'], $cronDate['day'], $cronDate['month'], '*'); $cron->saveCronFile(); // save to my_crontab cronfile $cron->saveToCrontab(); // adds all my_crontab jobs to system (replacing previous my_crontab jobs) }
/** * Close the crontab * * @access public * @return bool true if everything is ok, false is the lock file can't delete */ function closeCrontab() { if ($this->ctAccess == 'write') { $this->ct->writeCrontab(); } return $this->ctAccess == 'write' ? $this->unlockCrontab() : true; }
/** * A method to easily create a job from a crontab definition * * @param Crontab $crontab */ function createFromCrontab(&$crontab) { $this->crontabId = $crontab->getId(); $this->startTimestamp = time(); $this->code = $crontab->getCronJobCode(); $this->concurrent = $crontab->getConcurrent(); $this->implementationId = $crontab->getImplementationId(); }
/** * @covers Crontab::isDue */ public function testIsDue() { $cron = new Crontab(); $cron->setName('Created Test Entry')->setCommand('symfony')->setParameters('cache:clear --env=test')->setSchedule('* * * * *')->setLastRunAt(new DateTime('-10 minutes'))->save(); // Did not run this minute $this->assertTrue($cron->isDue()); // Reload from database $pk = $cron->getId(); CrontabPeer::clearInstancePool(); $cron = CrontabPeer::retrieveByPK($pk); $this->assertNotEmpty($cron); // Check correct Entry retrieved $this->assertEquals($pk, $cron->getId()); $this->assertTrue($cron->isDue()); // Already ran this minute $cron->setLastRunAt(new DateTime())->save(); $this->assertFalse($cron->isDue()); $cron->delete(); }
private function isDue($class, $method, $when) { $next = Crontab::factory($when)->getNextRunDate()->getTimestamp(); $row = Raw::ScheduleTask()->where(['class', '=', $class])->where(['method', '=', $method])->first(true); if (!$row) { $row = Raw::ScheduleTask()->create(['class' => $class, 'method' => $method, 'next' => (int) $next])->save(); } else { if ($row->next <= time()) { $row->setNext($next)->save(); return true; } } return false; }
public function set_next_run() { if (empty($this->interval) and empty($this->crontime)) { return; } if (!empty($this->crontime)) { $this->date_next_run = date('Y-m-d H:i:s', Crontab::parse($this->crontime)); } else { if (!empty($this->interval)) { $this->date_next_run = date('Y-m-d H:i:s', time() + $this->interval); } } return $this; }
/** * Finds next execution time(stamp) parsin crontab syntax, * after given starting timestamp (or current time if ommited) * * @param string $cron_string: * * 0 1 2 3 4 * * * * * * * - - - - - * | | | | | * | | | | +----- day of week (0 - 6) (Sunday=0) * | | | +------- month (1 - 12) * | | +--------- day of month (1 - 31) * | +----------- hour (0 - 23) * +------------- min (0 - 59) * @param int $after_timestamp timestamp [default=current timestamp] * @return int unix timestamp - next execution time will be greater * than given timestamp (defaults to the current timestamp) * @throws Kohana_Exception */ public static function parse($cron_string, $after_timestamp = NULL) { if (!Crontab::valid($cron_string)) { throw new Kohana_Exception('Invalid cron string: :string', array(':string' => $cron_string)); } if ($after_timestamp !== NULL and !Valid::numeric($after_timestamp)) { throw new Kohana_Exception("\$after_timestamp must be a valid unix timestamp (:string given)", array(':string' => $after_timestamp)); } $cron = preg_split("/[\\s]+/i", trim($cron_string)); $start = empty($after_timestamp) ? time() : $after_timestamp; $date = array('minutes' => self::_parse_cron_numbers($cron[0], 0, 59), 'hours' => self::_parse_cron_numbers($cron[1], 0, 23), 'dom' => self::_parse_cron_numbers($cron[2], 1, 31), 'month' => self::_parse_cron_numbers($cron[3], 1, 12), 'dow' => self::_parse_cron_numbers($cron[4], 0, 6)); // limited to time()+366 - no need to check more than 1year ahead for ($i = 0; $i <= 60 * 60 * 24 * 366; $i += 60) { if (in_array(intval(date('j', $start + $i)), $date['dom']) and in_array(intval(date('n', $start + $i)), $date['month']) and in_array(intval(date('w', $start + $i)), $date['dow']) and in_array(intval(date('G', $start + $i)), $date['hours']) and in_array(intval(date('i', $start + $i)), $date['minutes'])) { return $start + $i; } } return NULL; }
<?php require_once 'crontab.php'; $cron = new Crontab(); $cron->deleteJob($_POST['jobid']);
/** * 注册定时任务 */ protected static function register_timer() { swoole_timer_tick(60000, function () { Crontab::load_config(); }); swoole_timer_tick(1000, function ($interval) { Crontab::do_something($interval); }); }
/** * Deletes a particular model. * If deletion is successful, the browser will be redirected to the 'admin' page. * @param integer $id the ID of the model to be deleted */ public function actionDelete($id) { if(Yii::app()->request->isPostRequest) { // we only allow deletion via POST request // we only allow deletion via POST request $model=$this->loadModel($id); $cron = new Crontab('mail_crontab'); $jobs_obj = $cron->getJobs(); $cron->removeJob($model->student_attendence_email_cron_no); $cron->saveCronFile(); $cron->saveToCrontab(); $cronid=$model->student_attendence_email_cron_no; StudentAttendenceEmail::model()->updateCounters(array('student_attendence_email_cron_no'=>-1),'student_attendence_email_cron_no>'.$cronid); $this->loadModel($id)->delete(); // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if(!isset($_GET['ajax'])) $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin')); } else throw new CHttpException(400,'Invalid request. Please do not repeat this request again.'); }
<?php require_once 'crontab.php'; $cron = new Crontab(); $cron->deleteAllJobs();
function cronRun($cronPath, $eth = 'eth1', $errFilePath = '/tmp/cron.err') { $crontab = file($cronPath); $now = time(); delOldLog($now); $mailArr = array(); $newErrFile = $errFilePath . '.new'; foreach ($crontab as $cron) { $cron = ltrim($cron); if ($cron[0] === '#') { continue; } $slices = preg_split("/[\\s]+/", $cron, 6); if (count($slices) !== 6) { continue; } $cmd = trim(array_pop($slices)); $mailArr = getMailList($cmd); $cron_time = implode(' ', $slices); $next_time = Crontab::parse($cron_time, $now); if ($next_time !== $now) { continue; } $pid = pcntl_fork(); if ($pid == -1) { die('could not fork'); } else { if ($pid) { // we are the parent pcntl_wait($status, WNOHANG); //Protect against Zombie children } else { // we are the child // `$cmd`; $stdout = $stderr = $result = null; $result = Sexec($cmd, $stdout, $stderr, 360000); $stdout = rtrim($stdout); $stderr = rtrim($stderr); $exec_time = time() - $now; $now = date('Y-m-d H:i:s', $now); $suff = date('Y-m-d'); if (($fp = @fopen('/tmp/cron.log.' . $suff, 'a')) === FALSE) { echo 'error open cron log file'; exit(1); } @flock($fp, LOCK_EX); @fwrite($fp, "{$now} cmd:'{$cmd}' result code:{$result} Exec time:{$exec_time}\nstdout:{$stdout}\nstderr:{$stderr}\n"); @flock($fp, LOCK_UN); @fclose($fp); if ($result != '0') { writeTempError("{$now} cmd:'{$cmd}' result code:{$result} Exec time:{$exec_time}\nstdout:{$stdout}\nstderr:{$stderr}\n", $errFilePath); foreach ($mailArr as $mail) { $ip = trim(getIP($eth)); shell_exec('cat ' . $errFilePath . ' | sed \'s/\\r//\' >' . $newErrFile); shell_exec('export LANG=en_US.UTF-8;mail -s "crontab exec Error at ' . $ip . '" ' . $mail . '<' . $newErrFile); } } exit; } } } }
public static function params_tasktype($opt) { if (isset($opt["tasktype"])) { Crontab::$taskType = $opt["tasktype"]; } }
public function editOrganization() { global $myconn; $private_key = $this->private_key; $opOrg = $myconn->prepare("SELECT * FROM " . db_table_pref . "organizations WHERE ID=?") or die(mysqli_error($myconn)); $opOrg->bind_param('i', $this->OID); $opOrg->execute(); $opOrg->store_result(); if ($opOrg->num_rows == 0) { echo errMod('* ' . letheglobal_record_not_found . '', 'danger'); } else { $sr = new Statement_Result($opOrg); $opOrg->fetch(); } $this->errPrint = ''; # Remove Organization if (!$sr->Get('isPrimary')) { if (isset($_POST['del']) && $_POST['del'] == 'YES') { # Remove Folder deleteAll(LETHE_RESOURCE . DIRECTORY_SEPARATOR . $sr->Get('orgTag')); # Remove Blacklist $myconn->query("DELETE FROM " . db_table_pref . "blacklist WHERE OID=" . $this->OID . "") or die(mysqli_error($myconn)); # Remove Autoresponder Actions $myconn->query("DELETE FROM " . db_table_pref . "campaign_ar WHERE OID=" . $this->OID . "") or die(mysqli_error($myconn)); # Remove Campaign Groups $myconn->query("DELETE FROM " . db_table_pref . "campaign_groups WHERE OID=" . $this->OID . "") or die(mysqli_error($myconn)); # Remove Campaigns $myconn->query("DELETE FROM " . db_table_pref . "campaigns WHERE OID=" . $this->OID . "") or die(mysqli_error($myconn)); # Remove Organization Settings $myconn->query("DELETE FROM " . db_table_pref . "organization_settings WHERE OID=" . $this->OID . "") or die(mysqli_error($myconn)); # Remove Organization $myconn->query("DELETE FROM " . db_table_pref . "organizations WHERE ID=" . $this->OID . "") or die(mysqli_error($myconn)); # Reports $myconn->query("DELETE FROM " . db_table_pref . "reports WHERE OID=" . $this->OID . "") or die(mysqli_error($myconn)); # Short Codes $myconn->query("DELETE FROM " . db_table_pref . "short_codes WHERE OID=" . $this->OID . "") or die(mysqli_error($myconn)); # Form Fields $myconn->query("DELETE FROM " . db_table_pref . "subscribe_form_fields WHERE OID=" . $this->OID . "") or die(mysqli_error($myconn)); # Forms $myconn->query("DELETE FROM " . db_table_pref . "subscribe_forms WHERE OID=" . $this->OID . "") or die(mysqli_error($myconn)); # Subscriber Groups $myconn->query("DELETE FROM " . db_table_pref . "subscriber_groups WHERE OID=" . $this->OID . "") or die(mysqli_error($myconn)); # Subscribers $myconn->query("DELETE FROM " . db_table_pref . "subscribers WHERE OID=" . $this->OID . "") or die(mysqli_error($myconn)); # Tasks $myconn->query("DELETE FROM " . db_table_pref . "tasks WHERE OID=" . $this->OID . "") or die(mysqli_error($myconn)); # Templates $myconn->query("DELETE FROM " . db_table_pref . "templates WHERE OID=" . $this->OID . "") or die(mysqli_error($myconn)); # Unsubscribes $myconn->query("DELETE FROM " . db_table_pref . "unsubscribes WHERE OID=" . $this->OID . "") or die(mysqli_error($myconn)); # User Permissions $myconn->query("DELETE FROM " . db_table_pref . "user_permissions WHERE OID=" . $this->OID . "") or die(mysqli_error($myconn)); # Users $myconn->query("DELETE FROM " . db_table_pref . "users WHERE OID=" . $this->OID . "") or die(mysqli_error($myconn)); # Remove Cron Tasks include_once LETHE_ADMIN . DIRECTORY_SEPARATOR . 'classes/class.chronos.php'; $letChr = new Crontab(); $opCron = $myconn->query("SELECT * FROM " . db_table_pref . "chronos WHERE OID=" . $this->OID . "") or die(mysqli_error($myconn)); while ($opCronRs = $opCron->fetch_assoc()) { $letChr->removeJob($opCronRs['cron_command']); } $opCron->free(); # Remove Crons $myconn->query("DELETE FROM " . db_table_pref . "chronos WHERE OID=" . $this->OID . "") or die(mysqli_error($myconn)); # Done! header('Location: ?p=organizations/organization'); return false; die; } } if (!isset($_POST['org_name']) || empty($_POST['org_name'])) { $this->errPrint .= '* ' . organizations_please_enter_a_organization_name . '<br>'; } if (LETHE_AUTH_MODE == 2 && PRO_MODE) { if (!isset($_POST['org_max_user']) || !is_numeric($_POST['org_max_user'])) { $this->errPrint .= '* ' . organizations_please_enter_a_maximum_user_limit . '<br>'; } if (!isset($_POST['org_max_newsletter']) || !is_numeric($_POST['org_max_newsletter'])) { $this->errPrint .= '* ' . organizations_please_enter_a_maximum_newsletter_limit . '<br>'; } if (!isset($_POST['org_max_autoresponder']) || !is_numeric($_POST['org_max_autoresponder'])) { $this->errPrint .= '* ' . organizations_please_enter_a_maximum_autoresponder_limit . '<br>'; } if (!isset($_POST['org_max_subscriber']) || !is_numeric($_POST['org_max_subscriber'])) { $this->errPrint .= '* ' . organizations_please_enter_a_maximum_subscriber_limit . '<br>'; } if (!isset($_POST['org_max_subscriber_group']) || !is_numeric($_POST['org_max_subscriber_group'])) { $this->errPrint .= '* ' . organizations_please_enter_a_maximum_subscriber_group_limit . '<br>'; } if (!isset($_POST['org_max_subscribe_form']) || !is_numeric($_POST['org_max_subscribe_form'])) { $this->errPrint .= '* ' . organizations_please_enter_a_maximum_subscribe_form_limit . '<br>'; } if (!isset($_POST['org_max_blacklist']) || !is_numeric($_POST['org_max_blacklist'])) { $this->errPrint .= '* ' . organizations_please_enter_a_maximum_black_list_limit . '<br>'; } if (!isset($_POST['org_max_template']) || !is_numeric($_POST['org_max_template'])) { $this->errPrint .= '* ' . organizations_please_enter_a_maximum_template_limit . '<br>'; } if (!isset($_POST['org_max_shortcode']) || !is_numeric($_POST['org_max_shortcode'])) { $this->errPrint .= '* ' . organizations_please_enter_maximum_short_code_limit . '<br>'; } if (!isset($_POST['org_max_daily_limit']) || !is_numeric($_POST['org_max_daily_limit'])) { $this->errPrint .= '* ' . organizations_please_enter_a_daily_sending_limit . '<br>'; } if (!isset($_POST['org_standby_organization']) || !is_numeric($_POST['org_standby_organization'])) { $this->errPrint .= '* ' . organizations_please_enter_a_standby_time_for_organizations . '<br>'; } } else { $_POST['org_max_user'] = set_org_max_user; $_POST['org_max_newsletter'] = set_org_max_newsletter; $_POST['org_max_autoresponder'] = set_org_max_autoresponder; $_POST['org_max_subscriber'] = set_org_max_subscriber; $_POST['org_max_subscriber_group'] = set_org_max_subscriber_group; $_POST['org_max_subscribe_form'] = set_org_max_subscribe_form; $_POST['org_max_blacklist'] = set_org_max_blacklist; $_POST['org_max_template'] = set_org_max_template; $_POST['org_max_shortcode'] = set_org_max_shortcode; $_POST['org_max_daily_limit'] = set_org_max_daily_limit; $_POST['org_standby_organization'] = set_org_standby_organization; } /* Only For Super Admin */ if (LETHE_AUTH_MODE == 2) { if (!isset($_POST['org_submission_account']) || count($_POST['org_submission_account']) == 0) { $this->errPrint .= '* ' . organizations_please_choose_a_submission_account . '<br>'; } else { $_POST['org_submission_account'] = implode(',', $_POST['org_submission_account']); } } else { $_POST['org_submission_account'] = set_org_submission_account; } if (!isset($_POST['org_sender_title']) || empty($_POST['org_sender_title'])) { $this->errPrint .= '* ' . organizations_please_enter_a_sender_title . '<br>'; } if (!isset($_POST['org_reply_mail']) || !mailVal($_POST['org_reply_mail'])) { $this->errPrint .= '* ' . organizations_invalid_reply_mail . '<br>'; } if (!isset($_POST['org_test_mail']) || !mailVal($_POST['org_test_mail'])) { $this->errPrint .= '* ' . organizations_invalid_test_mail . '<br>'; } if (!isset($_POST['org_timezone']) || empty($_POST['org_timezone'])) { $this->errPrint .= '* ' . organizations_please_choose_a_timezone . '<br>'; } if (!isset($_POST['org_after_unsubscribe']) || !is_numeric($_POST['org_after_unsubscribe'])) { $this->errPrint .= '* ' . organizations_please_choose_a_unsubscribe_action . '<br>'; } if (!isset($_POST['org_verification']) || !is_numeric($_POST['org_verification'])) { $this->errPrint .= '* ' . organizations_please_choose_a_verification_method . '<br>'; } if (!isset($_POST['org_random_load']) || empty($_POST['org_random_load'])) { $_POST['org_random_load'] = ''; } else { $_POST['org_random_load'] = 1; } if (!isset($_POST['org_load_type']) || !is_numeric($_POST['org_load_type'])) { $this->errPrint .= '* ' . organizations_please_choose_a_load_type . '<br>'; } if ($this->errPrint == '') { /* Common Values */ $this->isPrimary = $sr->Get('isPrimary'); $billingDate = $this->billingDate == 0 ? '' : $this->billingDate; $orgTag = $this->orgTag == '' ? $sr->Get('orgTag') : $this->orgTag; $public_key = $this->public_key == '' ? $sr->Get('public_key') : $this->public_key; $private_key = $this->private_key == '' ? $sr->Get('private_key') : $this->private_key; # RSS Url if (!isset($_POST['org_rss_url']) || empty($_POST['org_rss_url'])) { # Define as system URL $_POST['org_rss_url'] = lethe_root_url . 'lethe.newsletter.php?pos=rss&oid=' . $public_key; } else { $_POST['org_rss_url'] = $_POST['org_rss_url']; } $addOrg = $myconn->prepare("UPDATE \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t" . db_table_pref . "organizations\n\t\t\t\t\t\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\t\t\t\t\t\t\torgTag=?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\torgName=?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tbillingDate=?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tisActive=1,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tpublic_key=?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tprivate_key=?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\trss_url=?\n\t\t\t\t\t\t\t\t\t\t\t WHERE\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tID=" . $sr->Get('ID') . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t") or die(mysqli_error($myconn)); $addOrg->bind_param('ssssss', $orgTag, $_POST['org_name'], $billingDate, $public_key, $private_key, $_POST['org_rss_url']); $addOrg->execute(); $addOrg->close(); /* Organization ID */ $orgID = $sr->Get('ID'); /* Load Settings */ global $LETHE_ORG_SET_VALS; $addSet = $myconn->prepare("UPDATE " . db_table_pref . "organization_settings SET set_val=? WHERE OID=? AND set_key=?") or die(mysqli_error($myconn)); foreach ($LETHE_ORG_SET_VALS as $k => $v) { if (!isset($_POST[$v])) { $_POST[$v] = constant('set_' . $v); } $addSet->bind_param('sis', $_POST[$v], $orgID, $v); $addSet->execute(); } $addSet->close(); unset($_POST); $this->isSuccess = 1; $this->errPrint = errMod('' . letheglobal_updated_successfully . '!', 'success'); } else { $this->errPrint = errMod($this->errPrint, 'danger'); } }
public function addCron($min = '*', $hour = '*', $dayOfMonth = '*', $month = '*', $dayOfWeek = '*', $cmd = '') { if (!in_array('exec', explode(', ', ini_get('disable_functions')))) { include_once dirname(__FILE__) . '/classes/Crontab.php'; $cron = new Crontab(get_current_user()); $cron->addCron($c_min, $c_hour, $dayOfMonth, $month, $dayOfWeek, $cmd); $cron->writeCrontab(); } else { echo '<div class="alert alert-error"><strong>' . Translate('EXEC function is disabled') . '</strong> ' . Translate('Creëer handmatig de conjob') . '<br /> Min: ' . $min . '<br /> Hour: ' . $hour . '<br /> Day of the month: ' . $dayOfMonth . '<br /> Month: ' . $month . '<br /> Day of the week: ' . $dayOfWeek . '<br /> Command: ' . $cmd . '<br /> </div>'; } }
/** * 解析启动模式参数 * @param $opt */ public static function params_s($opt) { //判断传入了s参数但是值,则提示错误 if (isset($opt["s"]) && !$opt["s"] || isset($opt["s"]) && !in_array($opt["s"], array("start", "stop", "restart"))) { Main::log_write("Please run: path/to/php main.php -s [start|stop|restart]"); } if (isset($opt["s"]) && in_array($opt["s"], array("start", "stop", "restart"))) { switch ($opt["s"]) { case "start": Crontab::start(); break; case "stop": Crontab::stop(); break; case "restart": Crontab::restart(); break; } } }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model=$this->loadModel($id); // comment the following line if AJAX validation is not needed $this->performAjaxValidation($model); if(isset($_POST['ScheduleTiming'])) { $model->attributes=$_POST['ScheduleTiming']; if($model->schedule_timing_minute==60) { $minute="*"; } else { $minute=$model->schedule_timing_minute; } if($model->schedule_timing_hour==24) { $hour="*"; } else { $hour=$model->schedule_timing_hour; } if($model->schedule_timing_date==32) { $date="*"; } else { $date=$model->schedule_timing_date; } $days=array("Sunday"=>7,"Monday"=>1,"Tuesday"=>2,"Wednesday"=>3,"Thursday"=>4,"Friday"=>5,"Saturday"=>6,"*"=>"*"); $day=$days[$model->schedule_timing_day]; $months=array('January'=>1,'February'=>2,'March'=>3,'April'=>4,'May'=>5,'June'=>6,'July'=>7,'August'=>8,'September'=>9,'October'=>10,'November'=>11,'December'=>12,'*'=>'*'); $month=$months[$model->schedule_timing_month]; $model->schedule_timing_name=$minute."-".$hour."-".$date."-".$model->schedule_timing_month."-".$model->schedule_timing_day; if($model->save()) { $crons=StudentSmsEmailDetails::model()->findAll(array('condition'=>'student_sms_email_details_schedule_time_id='.$model->schedule_timing_id)); $j = count($crons); $i = 0; foreach($crons as $cron) { if($cron->student_sms_email_details_purpose=="fees") { $period=$cron->academic_period_id; $sem=$cron->academic_name_id; $branch=$cron->branch_id; $div=$cron->division_id; $purpose=$cron->student_sms_email_details_purpose; $message=$cron->message_email_text; $user=$cron->created_by; $to=$cron->student_sms_email_details_fees_msg_type; $mobile=$cron->student_sms_email_details_to_mobile; $cronid=$cron->student_sms_email_details_cron_no-$i; $mycron = new Crontab('my_crontab'); $jobs_obj = $mycron->getJobs(); $mycron->removeJob($cronid); $mycron->saveCronFile(); $mycron->saveToCrontab(); StudentSmsEmailDetails::model()->updateCounters(array('student_sms_email_details_cron_no'=>-1),'student_sms_email_details_cron_no>'.$cronid); $mycron = new Crontab('my_crontab'); $cron->student_sms_email_details_cron_no=((count($mycron->getJobs()))); $cron->save(); $mycron->addJob(Yii::getPathOfAlias('webroot').'/protected/yiic feesschedulesms '.$period." ".$sem." ".$branch." ".$div." ".$purpose." \"$message\" ".$user." ".$to." ".$mobile , $minute, $hour,$date,$month,$day); $mycron->saveCronFile(); $mycron->saveToCrontab(); } else { $period=$cron->academic_period_id; $sem=$cron->academic_name_id; $branch=$cron->branch_id; $div=$cron->division_id; $purpose=$cron->student_sms_email_details_purpose; $user=$cron->created_by; $mobile=$cron->student_sms_email_details_to_mobile; $cronid=$cron->student_sms_email_details_cron_no-$i; $mycron = new Crontab('my_crontab'); $jobs_obj = $mycron->getJobs(); $mycron->removeJob($cronid); $mycron->saveCronFile(); $mycron->saveToCrontab(); StudentSmsEmailDetails::model()->updateCounters(array('student_sms_email_details_cron_no'=>-1),'student_sms_email_details_cron_no>'.$cronid); $mycron = new Crontab('my_crontab'); $cron->student_sms_email_details_cron_no=(count($mycron->getJobs())); $cron->save(); $mycron->addJob(Yii::getPathOfAlias('webroot').'/protected/yiic attendance '.$period." ".$sem." ".$branch." ".$div." ".$purpose." ".$user." ".$mobile,$minute,$hour,$date,$month,$day); $mycron->saveCronFile(); $mycron->saveToCrontab(); } $i++; } $backup_crons=DatabaseBackupCron::model()->findAll(array('condition'=>'database_backup_cron_schedule_time_id='.$model->schedule_timing_id)); $j = count($backup_crons); $i = 0; foreach($backup_crons as $cron) { $cronid=$cron->database_backup_cron_no-$i; $mycron = new Crontab('backup_crontab'); $jobs_obj = $mycron->getJobs(); $mycron->removeJob($cronid); $mycron->saveCronFile(); $mycron->saveToCrontab(); DatabaseBackupCron::model()->updateCounters(array('database_backup_cron_no'=>-1),'database_backup_cron_no>'.$cronid); $mycron = new Crontab('backup_crontab'); $cron->database_backup_cron_no=((count($mycron->getJobs()))); $cron->save(); $mycron->addJob(Yii::getPathOfAlias('webroot').'/protected/yiic backup' , $minute, $hour,$date,$month,$day); $mycron->saveCronFile(); $mycron->saveToCrontab(); $i++; } $this->redirect(array('view','id'=>$model->schedule_timing_id)); } } $this->render('update',array( 'model'=>$model, )); }
function test_remove_all_jobs() { $crontab = new Crontab($this->config); $times = array('0 * * * *', '0 12 * * *', '0 12 * 2 *'); $action = 'test_remove_all'; foreach ($times as $time) { $crontab->add_job($time, $action); } $file_items = explode("\n", read_file($crontab->cronfile)); foreach ($times as $time) { $job = $time . ' ' . $crontab->php_path . ' ' . $crontab->cli_path . $action; $this->assertTrue(in_array($job, $file_items)); } //actual test $crontab->remove_all_jobs($action); $file_items = explode("\n", read_file($crontab->cronfile)); $job = $time . ' ' . $crontab->php_path . ' ' . $crontab->cli_path . $action; $this->assertFalse(in_array($job, $file_items)); }
/** * Deletes a particular model. * If deletion is successful, the browser will be redirected to the 'admin' page. * @param integer $id the ID of the model to be deleted */ public function actionDelete($id) { $model=$this->loadModel($id); $cron = new Crontab('backup_crontab'); $jobs_obj = $cron->getJobs(); $cron->removeJob($model->database_backup_cron_no); $cron->saveCronFile(); $cron->saveToCrontab(); $cronid=$model->database_backup_cron_no; DatabaseBackupCron::model()->updateCounters(array('database_backup_cron_no'=>-1),'database_backup_cron_no>'.$cronid); // we only allow deletion via POST request $this->loadModel($id)->delete(); // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if(!isset($_GET['ajax'])) $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin')); }
/** * 解析配置文件位置参数 * @param $opt */ public static function params_c($opt) { if (isset($opt["c"]) && $opt["c"]) { Crontab::$config_file = $opt["c"]; } if (isset($opt["config"]) && $opt["config"]) { Crontab::$config_file = $opt["config"]; } if (empty(Crontab::$config_file)) { Crontab::$config_file = ROOT_PATH . "config/crontab.php"; } }
function configsave() { $tempcacheid = time(); if (be("post", "app_vodviewtype") == "2") { SpecialChar(be("post", "app_vodlistpath")); SpecialChar(be("post", "app_vodpath")); SpecialChar(be("post", "app_vodplaypath")); SpecialChar(be("post", "app_vodtopicpath")); } if (be("post", "app_artviewtype", "post") == "2") { SpecialChar(be("post", "app_artlistpath")); SpecialChar(be("post", "app_artpath")); SpecialChar(be("post", "app_arttopicpath")); } $timming = trim(be("post", "app_timming")); if (strpos(strtolower(PHP_OS), 'linux') !== false) { $command = "*/5 * * * * wget http://" . $_SERVER['HTTP_HOST'] . '/inc/timming.php >> /dev/null 2>&1'; if ($timming === '0') { Crontab::deleteCommand($command, 'http://' . $_SERVER['HTTP_HOST'] . '/inc/timming.php'); } else { Crontab::replaceCommand($command, 'http://' . $_SERVER['HTTP_HOST'] . '/inc/timming.php'); } } $str = "<" . "?php" . "\n"; $str .= "define(\"app_sitename\"," . chr(34) . trim(be("post", "app_sitename")) . chr(34) . "); //网站名称" . "\n"; $str .= "define(\"app_installdir\"," . chr(34) . trim(be("post", "app_installdir")) . chr(34) . "); //网站路径" . "\n"; $str .= "define(\"app_siteurl\"," . chr(34) . trim(be("post", "app_siteurl")) . chr(34) . "); //网站域名地址" . "\n"; $str .= "define(\"app_keywords\"," . chr(34) . trim(be("post", "app_keywords")) . chr(34) . "); //网站关键字" . "\n"; $str .= "define(\"app_description\"," . chr(34) . trim(be("post", "app_description")) . chr(34) . "); //网站描述信息" . "\n"; $str .= "define(\"app_templatedir\"," . chr(34) . trim(be("post", "app_templatedir")) . chr(34) . "); //模板目录" . "\n"; $str .= "define(\"app_htmldir\"," . chr(34) . trim(be("post", "app_htmldir")) . chr(34) . "); //模板html目录" . "\n"; $str .= "define(\"app_cache\"," . trim(be("post", "app_cache")) . "); //是否开启缓存" . "\n"; $str .= "define(\"app_cachetime\"," . trim(be("post", "app_cachetime")) . "); //缓存时间" . "\n"; $str .= "define(\"app_cacheid\"," . chr(34) . trim($tempcacheid) . chr(34) . "); //缓存标示" . "\n"; $str .= "define(\"app_picpath\"," . trim(be("post", "app_picpath")) . "); //图片保存路径方式,0=默认,1=按月份,2=按日期,3=每目录500图片,超过自动创建新目录" . "\n"; $str .= "define(\"app_dbtype\"," . chr(34) . trim(be("post", "app_dbtype")) . chr(34) . "); //数据库类型: 值分别为 access ; mssql" . "\n"; $str .= "define(\"app_dbpath\"," . chr(34) . trim(be("post", "app_dbpath")) . chr(34) . "); //access数据库路径" . "\n"; $str .= "define(\"app_dbserver\"," . chr(34) . trim(be("post", "app_dbserver")) . chr(34) . "); //SQL数据库服务器地址" . "\n"; $str .= "define(\"app_dbname\"," . chr(34) . trim(be("post", "app_dbname")) . chr(34) . "); \t\t\t\t\t //SQL数据库名称" . "\n"; $str .= "define(\"app_dbuser\"," . chr(34) . trim(be("post", "app_dbuser")) . chr(34) . "); //SQL数据库用户名" . "\n"; $str .= "define(\"app_dbpass\"," . chr(34) . trim(be("post", "app_dbpass")) . chr(34) . "); \t\t\t\t\t //SQL数据库密码" . "\n"; $str .= "define(\"app_tablepre\"," . chr(34) . trim(be("post", "app_tablepre")) . chr(34) . "); \t\t\t\t\t //表结构前缀" . "\n"; $str .= "define(\"app_icp\"," . chr(34) . trim(be("post", "app_icp")) . chr(34) . "); //网站备案号" . "\n"; $str .= "define(\"app_email\"," . chr(34) . trim(be("post", "app_email")) . chr(34) . "); //站长邮箱" . "\n"; $str .= "define(\"app_qq\"," . chr(34) . trim(be("post", "app_qq")) . chr(34) . "); //站长qq" . "\n"; $str .= "define(\"app_user\"," . trim(be("post", "app_user")) . "); //是否开启会员验证0关闭,1开启" . "\n"; $str .= "define(\"app_dynamiccache\"," . trim(be("post", "app_dynamiccache")) . "); //是否开启动态文件缓存0关闭,1开启" . "\n"; $str .= "define(\"app_timming\"," . trim(be("post", "app_timming")) . "); //是否开启定时任务0关闭,1开启" . "\n"; $str .= "define(\"app_install\",1); //是否已经安装本程序0未安装,1已安装" . "\n"; $str .= "define(\"app_safecode\"," . chr(34) . trim(be("post", "app_safecode")) . chr(34) . "); //后台登录安全码" . "\n\n"; $str .= "define(\"app_vodviewtype\"," . trim(be("post", "app_vodviewtype")) . "); //视频首页、地图 浏览模式, 0=仿伪静态模式,1=asp动态模式,2=静态模式,3=rewrite伪静态" . "\n"; $str .= "define(\"app_vodlistviewtype\"," . trim(be("post", "app_vodlistviewtype")) . "); //视频列表页 浏览模式, 同上" . "\n"; $str .= "define(\"app_vodtopicviewtype\"," . trim(be("post", "app_vodtopicviewtype")) . "); //视频专题首页、列表 浏览模式, 同上" . "\n"; $str .= "define(\"app_vodcontentviewtype\"," . trim(be("post", "app_vodcontentviewtype")) . "); //视频内容页 浏览模式, 同上" . "\n"; $str .= "define(\"app_vodplayviewtype\"," . trim(be("post", "app_vodplayviewtype")) . "); //视频播放页 浏览模式, 0=仿伪静态模式,1=asp动态模式,2=rewrite伪静态,3=静态每数据一页,4=静态每集一页,5=静态每组一页,6=静态全站一页" . "\n"; $str .= "define(\"app_vodsuffix\"," . chr(34) . trim(be("post", "app_vodsuffix")) . chr(34) . "); //生成视频静态文件后缀名" . "\n"; $str .= "define(\"app_vodmakeinterval\"," . trim(be("post", "app_vodmakeinterval")) . "); //生成视频静态页面间隔" . "\n"; $str .= "define(\"app_playtype\"," . trim(be("post", "app_playtype")) . "); //0=有内容页播放,1=无内容页播放" . "\n"; $str .= "define(\"app_encrypt\"," . trim(be("post", "app_encrypt")) . "); //是否加密播放地址 0不加密,1 escape加密,2 base64加密" . "\n"; $str .= "define(\"app_playisopen\"," . trim(be("post", "app_playisopen")) . "); //否弹窗播放 0普通播放,1弹窗播放" . "\n"; $str .= "define(\"app_vodlistpath\"," . chr(34) . trim(be("post", "app_vodlistpath")) . chr(34) . "); //视频分类页面目录" . "\n"; $str .= "define(\"app_vodpath\"," . chr(34) . trim(be("post", "app_vodpath")) . chr(34) . "); //视频内容页面目录" . "\n"; $str .= "define(\"app_vodplaypath\"," . chr(34) . trim(be("post", "app_vodplaypath")) . chr(34) . "); //视频播放页面目录" . "\n"; $str .= "define(\"app_vodtopicpath\"," . chr(34) . trim(be("post", "app_vodtopicpath")) . chr(34) . "); //视频专题页目录" . "\n\n"; $str .= "define(\"app_artviewtype\"," . trim(be("post", "app_artviewtype")) . "); //文章首页、地图 浏览模式, 0=仿伪静态模式,1=asp动态模式,2=静态模式,3=rewrite伪静态" . "\n"; $str .= "define(\"app_artlistviewtype\"," . trim(be("post", "app_artlistviewtype")) . "); //文章列表页 浏览模式, 同上" . "\n"; $str .= "define(\"app_arttopicviewtype\"," . trim(be("post", "app_arttopicviewtype")) . "); //文章专题首页、列表 浏览模式, 同上" . "\n"; $str .= "define(\"app_artcontentviewtype\"," . trim(be("post", "app_artcontentviewtype")) . "); //文章内容页 浏览模式, 同上" . "\n"; $str .= "define(\"app_artsuffix\"," . chr(34) . trim(be("post", "app_artsuffix")) . chr(34) . "); //生成文章静态文件后缀名" . "\n"; $str .= "define(\"app_artmakeinterval\"," . trim(be("post", "app_artmakeinterval")) . "); //生成文章静态页面间隔" . "\n"; $str .= "define(\"app_artlistpath\"," . chr(34) . trim(be("post", "app_artlistpath")) . chr(34) . "); //文章列表目录" . "\n"; $str .= "define(\"app_artpath\"," . chr(34) . trim(be("post", "app_artpath")) . chr(34) . "); //文章页面目录" . "\n"; $str .= "define(\"app_arttopicpath\"," . chr(34) . trim(be("post", "app_arttopicpath")) . chr(34) . "); //文章专题页目录" . "\n\n"; $str .= "define(\"app_watermark\"," . trim(be("post", "app_watermark")) . "); //上传的图片是否添加水印 0关闭,1开启" . "\n"; $str .= "define(\"app_waterlocation\"," . trim(be("post", "app_waterlocation")) . "); //水印在图片的位置" . "\n"; $str .= "define(\"app_waterfont\"," . chr(34) . trim(be("post", "app_waterfont")) . chr(34) . "); //水印文字" . "\n"; $str .= "define(\"app_gbook\"," . trim(be("post", "app_gbook")) . "); //是否开启留言本 0关闭,1开启" . "\n"; $str .= "define(\"app_gbooknum\"," . trim(be("post", "app_gbooknum")) . "); //留言本每页显示数量" . "\n"; $str .= "define(\"app_gbooktime\"," . trim(be("post", "app_gbooktime")) . "); //留言时间间隔" . "\n"; $str .= "define(\"app_gbookverify\"," . trim(be("post", "app_gbookverify")) . "); //留言时是否开启验证码0关闭,1开启" . "\n"; $str .= "define(\"app_gbookaudit\"," . trim(be("post", "app_gbookaudit")) . "); //留言时是否需要审核0关闭,1开启" . "\n"; $str .= "define(\"app_comment\"," . trim(be("post", "app_comment")) . "); //是否开启评论 0关闭,1开启" . "\n"; $str .= "define(\"app_commentnum\"," . trim(be("post", "app_commentnum")) . "); //评论每页显示数量" . "\n"; $str .= "define(\"app_commenttime\"," . trim(be("post", "app_commenttime")) . "); //评论时间间隔" . "\n"; $str .= "define(\"app_commentverify\"," . trim(be("post", "app_commentverify")) . "); //评论时是否开启验证码0关闭,1开启" . "\n"; $str .= "define(\"app_commentaudit\"," . trim(be("post", "app_commentaudit")) . "); //评论时是否需要审核0关闭,1开启" . "\n"; $str .= "define(\"app_mood\"," . trim(be("post", "app_mood")) . "); //是否开启心情 0关闭,1开启" . "\n"; $str .= "define(\"app_pagenum\"," . trim(be("post", "app_pagenum")) . "); //后台列表每页显示个数" . "\n"; $str .= "define(\"app_filter\"," . chr(34) . trim(be("post", "app_filter")) . chr(34) . "); //评论和留言本过滤内容" . "\n"; $str .= "define(\"app_reg\"," . trim(be("post", "app_reg")) . "); //是否开启会员注册 1开启,0关闭" . "\n"; $str .= "define(\"app_regpoint\"," . trim(be("post", "app_regpoint")) . "); //用户注册赠送点数" . "\n"; $str .= "define(\"app_regstate\"," . trim(be("post", "app_regstate")) . "); //注册用户默认状态,1激活,0锁定" . "\n"; $str .= "define(\"app_popularize\"," . trim(be("post", "app_popularize")) . "); //推广1个人获取积分数" . "\n"; $str .= "define(\"app_popularizestate\"," . trim(be("post", "app_popularizestate")) . "); //是否开启推广赚积分1,开启 0关闭" . "\n"; $str .= "define(\"app_reggroup\"," . trim(be("post", "app_reggroup")) . "); //用户注册默认会员组" . "\n\n"; $str .= "define(\"app_api\"," . trim(be("post", "app_api")) . "); //接口API开关1开启,0关闭" . "\n"; $str .= "define(\"app_apicjflag\"," . chr(34) . trim(be("post", "app_apicjflag")) . chr(34) . "); //联盟图片域名,以http:开头,/结尾,不包含upload目录" . "\n"; $str .= "define(\"app_apitypefilter\"," . chr(34) . trim(be("post", "app_apitypefilter")) . chr(34) . "); //过滤分类参数,SQL查询条件例如 and t_hide=0" . "\n"; $str .= "define(\"app_apivodfilter\"," . chr(34) . trim(be("post", "app_apivodfilter")) . chr(34) . "); //过滤数据参数,SQL查询条件例如 and d_hide=0" . "\n"; $str .= "define(\"app_apipagenum\"," . trim(be("post", "app_apipagenum")) . "); //数据每页显示量" . "\n"; $str .= "?" . ">"; fwrite(fopen("../inc/config.php", "wb"), $str); //写入ftp配置 $str = "<" . "?php" . "\n"; $str .= "define(\"app_ftp\"," . trim(be("post", "app_ftp")) . "); //ftp开关" . "\n"; $str .= "define(\"app_ftphost\"," . chr(34) . trim(be("post", "app_ftphost")) . chr(34) . "); //ftp主机ip" . "\n"; $str .= "define(\"app_ftpuser\"," . chr(34) . trim(be("post", "app_ftpuser")) . chr(34) . "); //ftp帐号" . "\n"; $str .= "define(\"app_ftppass\"," . chr(34) . trim(be("post", "app_ftppass")) . chr(34) . "); //ftp密码" . "\n"; $str .= "define(\"app_ftpdir\"," . chr(34) . trim(be("post", "app_ftpdir")) . chr(34) . "); //ftp目录" . "\n"; $str .= "define(\"app_ftpport\"," . chr(34) . trim(be("post", "app_ftpport")) . chr(34) . "); //ftp端口" . "\n"; $str .= "define(\"app_ftpurl\"," . chr(34) . trim(be("post", "app_ftpurl")) . chr(34) . "); //ftp远程附件访问地址" . "\n"; $str .= "define(\"app_ftpdel\"," . trim(be("post", "app_ftpdel")) . "); //上传成功后是否删除本地文件" . "\n"; $str .= "?" . ">"; fwrite(fopen("../inc/ftp.php", "wb"), $str); echo "配置修改成功"; }
$module = 'crontab'; $functions = get_extension_funcs($module); echo "Functions available in the test extension:$br\n"; foreach($functions as $func) { echo $func."$br\n"; } echo "$br\n"; $function = 'confirm_' . $module . '_compiled'; if (extension_loaded($module)) { $str = $function($module); } else { $str = "Module $module is not compiled into PHP"; } echo "$str\n"; */ $c = new Crontab(); $a = array('* * * * *' => 'callback', '*/1 * * * *' => function ($id) { print_r(Crontab::info()); }); $b = array('*/2 * * * *' => function ($id) { $time = date("Y-m-d H:i:s"); echo "hello crtontab b {$id}, {$time}!\n"; }); var_dump($c->add($a)); var_dump($c->add($b)); var_dump($c->add($b)); var_dump($c->add($b)); var_dump($c->add($b)); var_dump($c->add($b)); var_dump($c->add("* * * * *", "callback")); var_dump($c->add("* * * * *", function ($id) {
$debugs[] = '* Current Date is: ' . date("Y-m-d H:i:s"); /* Submission Account Limit Resetter */ $opSubAcc = $myconn->query("SELECT * FROM " . db_table_pref . "submission_accounts WHERE isActive=1 AND daily_reset<'" . date("Y-m-d H:i:s") . "'") or die(mysqli_error($myconn)); while ($opSubAccRs = $opSubAcc->fetch_assoc()) { $newReset = date("Y-m-d H:i:s", strtotime(date("Y-m-d H:i:s") . "+" . $opSubAccRs['limit_range'] . " minutes")); $myconn->query("UPDATE " . db_table_pref . "submission_accounts SET daily_sent=0, daily_reset='" . $newReset . "' WHERE ID=" . $opSubAccRs['ID'] . "") or die(mysqli_error($myconn)); } $opSubAcc->free(); $debugs[] = '* Submission Account Limits Controlled'; /* Organization Daily Limit Resetter */ $newReset = date("Y-m-d H:i:s", strtotime(date("Y-m-d H:i:s") . "+1 day")); if ($myconn->query("UPDATE " . db_table_pref . "organizations SET daily_sent=0, daily_reset='" . $newReset . "' WHERE isActive=1 AND daily_reset<'" . date("Y-m-d H:i:s") . "'")) { $debugs[] = '* Organization Daily Limit Reset'; } /* Task List Modifier */ $letChr = new Crontab(); $currJobs = $letChr->getJobs(); $remJobs = array(); $addJobs = array(); $opTasks = $myconn->query("SELECT * FROM " . db_table_pref . "chronos ORDER BY pos DESC") or die(mysqli_error($myconn)); while ($opTasksRs = $opTasks->fetch_assoc()) { /* Remove Crons */ if ($opTasksRs['pos'] == 1) { if ($letChr->doesJobExist($opTasksRs['cron_command'])) { $remJobs[] = $opTasksRs['cron_command']; $myconn->query("DELETE FROM " . db_table_pref . "chronos WHERE ID=" . $opTasksRs['ID'] . ""); $debugs[] = '* Removed Cron: ' . $opTasksRs['cron_command']; } else { $debugs[] = '* There No Expired Cron Command Found'; } } else {
<?php require_once 'crontab.php'; $cron = new Crontab(); if (isset($_POST['minute']) && $_POST['minute'] != '') { $cron->onMinute($_POST['minute']); } if (isset($_POST['hour']) && $_POST['hour'] != '') { $cron->onHour($_POST['hour']); } if (isset($_POST['month']) && $_POST['month'] != '') { $cron->onMonth($_POST['month']); } if (isset($_POST['dayweek']) && $_POST['dayweek'] != '') { $cron->onDayOfWeek($_POST['dayweek']); } if (isset($_POST['daymonth']) && $_POST['daymonth'] != '') { $cron->onDayOfMonth($_POST['daymonth']); } if (isset($_POST['command']) && $_POST['command'] != '') { $cron->doJob($_POST['command']); } if ($cron->activate()) { echo json_encode($cron); } else { echo FALSE; }
$orgLethe->addOrganization(); } # User if (cntData("SELECT ID FROM " . $db_prefix . "users") == 0) { $opOr = $myconn->query("SELECT ID FROM " . $db_prefix . "organizations"); $opOrRs = $opOr->fetch_assoc(); $usrLethe = new lethe(); $usrLethe->onInstall = true; $usrLethe->isMaster = 1; $usrLethe->auth_mode = 2; $usrLethe->isPrimary = 1; $usrLethe->OID = $opOrRs['ID']; $usrLethe->addUser(); } # Main Cron $letChr = new Crontab(); $mainCroner = "* * * * * curl -s '" . lethe_root_url . "chronos/lethe.php' >/dev/null 2>&1"; $letChr->addJob($mainCroner); die('<script>$("#myLethe").attr("disabled",true);</script>' . errMod('Lethe Successfully Installed on Your System!<br>Dont Forget to Remove <strong>install.php</strong> File!', 'success')); } else { die('<script>$("#myLethe").attr("disabled",false);</script>' . errMod($errors, 'danger')); } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> <title>Lethe Newsletter & Mailing System Installation</title>
#!/bin/bash <?php /** * Created by PhpStorm. * User: Jenner * Date: 2015/10/6 * Time: 16:12 */ require dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'; try { $crontab = new Crontab(); $crontab->start(); } catch (Exception $e) { $crontab->keepPidFile(); echo "Exception:" . $e->getMessage() . PHP_EOL; echo $e->getTraceAsString() . PHP_EOL; } class Crontab { /** * @var \Jenner\Crontab\AbstractDaemon */ protected $daemon; /** * @var array */ protected $params; /** * @var string crontab missions config file */ protected $config_file;
public static function parms_worker($opt) { if (isset($opt["worker"])) { Crontab::$worker = true; } }
/** * Deletes a particular model. * If deletion is successful, the browser will be redirected to the 'admin' page. * @param integer $id the ID of the model to be deleted */ public function actionDelete($id) { $model=$this->loadModel($id); $cron = new Crontab('my_crontab'); $jobs_obj = $cron->getJobs(); $cron->removeJob($model->student_sms_email_details_cron_no); $cron->saveCronFile(); $cron->saveToCrontab(); $cronid=$model->student_sms_email_details_cron_no; StudentSmsEmailDetails::model()->updateCounters(array('student_sms_email_details_cron_no'=>-1),'student_sms_email_details_cron_no>'.$cronid); $this->loadModel($id)->delete(); // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if(!isset($_GET['ajax'])) $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('scheduleMessages')); }
/** *重启 */ public static function restart() { self::stop(); self::$daemon = true; self::start(); }
<?php require_once 'crontab.php'; $cron = new Crontab(); $active = $cron->listJobs(); echo json_encode($active);