function cron_run($cronid = 0) { if (empty($cronid)) { $cron = pdo_fetch('SELECT * FROM ' . tablename('cron') . ' WHERE available > 0 AND nextrun <= ' . TIMESTAMP . ' ORDER BY nextrun ASC'); } else { $cron = pdo_fetch('SELECT * FROM ' . tablename('cron') . ' WHERE cronid = :id', array(':id' => intval($cronid))); } if (empty($cron)) { return false; } if ($cron['type'] == 'system') { //定义系统内置的计划任务文件放在哪个路径 $cronfile = IA_ROOT . '/cron/' . $cron['filename']; } elseif ($cron['type'] == 'module') { //定义模块的计划任务文件放在哪个路径 $cronfile = IA_ROOT . '/cron/' . $cron['filename']; } if (is_file($cronfile)) { $cron['minute'] = explode("\t", $cron['minute']); //设置下次执行时间 cron_setnexttime($cron); @set_time_limit(1000); //@ignore_user_abort(TRUE); if (!@(include $cronfile)) { return false; } } }
function cron_run($id) { global $_W; $cron = pdo_get('core_cron', array('uniacid' => $_W['uniacid'], 'id' => $id)); if (empty($cron)) { return false; } $extra = array(); $extra['Host'] = $_SERVER['HTTP_HOST']; load()->func('communication'); $urlset = parse_url($_W['siteurl']); $urlset = pathinfo($urlset['path']); $response = ihttp_request('http://127.0.0.1/' . $urlset['dirname'] . '/' . url('cron/entry', array('id' => $cron['cloudid'])), array(), $extra); $response = json_decode($response['content'], true); if (is_error($response['message'])) { return $response['message']; } else { cron_setnexttime($cron); $cron_new = pdo_get('core_cron', array('uniacid' => $_W['uniacid'], 'id' => $id)); if (empty($cron_new)) { return true; } if ($cron_new['status'] != $cron['status'] || $cron_new['lastruntime'] != $cron['lastruntime'] || $cron_new['nextruntime'] != $cron['nextruntime']) { load()->model('cloud'); $cron_new['id'] = $cron_new['cloudid']; $status = cloud_cron_update($cron_new); if (is_error($status)) { return $status; } } } return true; }