Запись [f:main/cron.php] < dev.sky.1.001
Версия 1.001
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 | <?php define('START', 'cron'); function at($cron = '') { # Minutes Hours Days Months WeekDays-0=sunday * or 12 or */3 or 1,2,3 $ary = array_values(getdate()); $now = array_splice($ary, 1, 5); $_ = $now[3]; $now[3] = $now[4]; $now[4] = $_; # result: 0-min 1-hor 2-mday 3-mon 4-wday $com = preg_split("/\s+/", $cron); for ($i = 0; $i < 5; $i++) { if (!isset($com[$i]) || $com[$i] === '*' || $com[$i] === '') continue; if (isset($com[$i][1]) && $com[$i][1] == '/') { if ($now[$i] % substr($com[$i], 2) == 0) continue; else return false; } $digs = explode(',', $com[$i]); $ret = false; foreach ($digs as $dig) $dig == $now[$i] && $ret = true; if (!$ret) return false; } return true; } function lsql($sql) { $GLOBALS['log'][] = sprintf('%s: %s <= %s', NOW, sql($sql), $sql); } chdir(realpath(__DIR__ . '/..')); require 'main/conf.php'; $log = []; $sky = new SKY; extract($sky->load(), EXTR_PREFIX_ALL | EXTR_REFS, 's') or exit('err mem'); if ($sky->debug) require 'main/debug.php'; if (at('0 23')) lsql("delete from visitors where dt_l + $s_clear < now()"); at('59 23') && sql("+select 'do work once at the end of day'"); # sample2 if (at('1 0')) $sky->s_email_cnt = 0; if (at('3 3')) require 'main/c_sitemap.php'; $sky->save([ 'cron_dt' => sprintf("%s, execution time: %01.3f sec, SQL nums in cron tasks: $sky->qn", NOW, microtime(true) - START_TS), 'online' => sql("+select count(1) from visitors where dt_l > now() - interval $s_visit minute"), ]); lsql("+select 'test'"); $log && sqlf("update memory set tmemo=substr(concat(%s,'\n',tmemo),1,10000) where id=2", escape(implode("\n", $log))); |
• N1: WRITE FILE: main/c_summer.php
001 002 003 004 005 006 007 008 009 010 011 012 013 014 | <?php define('START', 'cron'); chdir(realpath(__DIR__ . '/..')); require 'main/conf.php'; $sky = new SKY; extract($sky->load(), EXTR_PREFIX_ALL | EXTR_REFS, 's') or exit('err mem'); if ($sky->debug) require 'main/debug.php'; $summer = NOW . ': Summer time changed for MySQL'; $tze = round((strtotime(NOW) - strtotime(sql("+select now()"))) / 3600) and preg_match("/^([\-\+]\d):(\d\d)$/", $sky->s_sql_tz, $m) and $sky->s_sql_tz = (($n = $m[1] + $tze) >= 0 ? '+' : '') . "$n:$m[2]" and sql("update memory set tmemo=substr(concat('$summer','\n',tmemo),1,10000) where id=2"); |