本文整理汇总了PHP中CMain::ForkActions方法的典型用法代码示例。如果您正苦于以下问题:PHP CMain::ForkActions方法的具体用法?PHP CMain::ForkActions怎么用?PHP CMain::ForkActions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CMain
的用法示例。
在下文中一共展示了CMain::ForkActions方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ExecuteEvents
function ExecuteEvents()
{
$err_mess = "<br>Class: CEvent<br>File: ".__FILE__."<br>Function: CheckEvents<br>Line: ";
global $DB, $CACHE_MANAGER;
if(defined("FX_FORK_AGENTS_AND_EVENTS_FUNCTION"))
{
if(CMain::ForkActions(array("CEvent", "ExecuteEvents")))
return "";
}
}
示例2: ExecuteEvents
function ExecuteEvents()
{
$err_mess = "<br>Class: CEvent<br>File: " . __FILE__ . "<br>Function: CheckEvents<br>Line: ";
global $DB, $CACHE_MANAGER;
if (defined("BX_FORK_AGENTS_AND_EVENTS_FUNCTION")) {
if (CMain::ForkActions(array("CEvent", "ExecuteEvents"))) {
return "";
}
}
$uniq = COption::GetOptionString("main", "server_uniq_id", "");
if (strlen($uniq) <= 0) {
$uniq = md5(uniqid(rand(), true));
COption::SetOptionString("main", "server_uniq_id", $uniq);
}
$bulk = intval(COption::GetOptionString("main", "mail_event_bulk", 5));
if ($bulk <= 0) {
$bulk = 5;
}
$strSql = "SELECT 'x' " . "FROM b_event " . "WHERE SUCCESS_EXEC='N' " . "LIMIT 1";
$db_result_event = $DB->Query($strSql);
if ($db_result_event->Fetch()) {
$db_lock = $DB->Query("SELECT GET_LOCK('" . $uniq . "_event', 0) as L");
$ar_lock = $db_lock->Fetch();
if ($ar_lock["L"] == "0") {
return "";
}
} else {
if (CACHED_b_event !== false) {
$CACHE_MANAGER->Set("events", true);
}
return "";
}
$strSql = "\n\t\t\tSELECT ID, C_FIELDS, EVENT_NAME, MESSAGE_ID, LID, DATE_FORMAT(DATE_INSERT, '%d.%m.%Y %H:%i:%s') as DATE_INSERT, DUPLICATE\n\t\t\tFROM b_event\n\t\t\tWHERE SUCCESS_EXEC='N'\n\t\t\tORDER BY ID\n\t\t\tLIMIT " . $bulk;
$rsMails = $DB->Query($strSql);
while ($arMail = $rsMails->Fetch()) {
$flag = CEvent::HandleEvent($arMail);
/*
'0' - нет шаблонов (не нужно было ничего отправл¤ть)
'Y' - все отправлены
'F' - все не смогли быть отправлены
'P' - частично отправлены
*/
$strSql = "\n\t\t\t\tUPDATE b_event SET\n\t\t\t\t\tDATE_EXEC = now(),\n\t\t\t\t\tSUCCESS_EXEC = '{$flag}'\n\t\t\t\tWHERE\n\t\t\t\t\tID = " . $arMail["ID"];
$DB->Query($strSql, false, $err_mess . __LINE__);
}
$DB->Query("SELECT RELEASE_LOCK('" . $uniq . "_event')");
}
示例3: ExecuteAgents
public static function ExecuteAgents($str_crontab)
{
global $DB, $CACHE_MANAGER, $pPERIOD;
if (defined("BX_FORK_AGENTS_AND_EVENTS_FUNCTION")) {
if (CMain::ForkActions(array("CAgent", "ExecuteAgents"), array($str_crontab))) {
return "";
}
}
$saved_time = 0;
$cache_id = "agents" . $str_crontab;
if (CACHED_b_agent !== false && $CACHE_MANAGER->Read(CACHED_b_agent, $cache_id, "agents")) {
$saved_time = $CACHE_MANAGER->Get($cache_id);
if (time() < $saved_time) {
return "";
}
}
$uniq = CMain::GetServerUniqID();
$strSql = "\n\t\t\tSELECT 'x'\n\t\t\tFROM b_agent\n\t\t\tWHERE\n\t\t\t\tACTIVE = 'Y'\n\t\t\t\tAND NEXT_EXEC <= now()\n\t\t\t\tAND (DATE_CHECK IS NULL OR DATE_CHECK <= now())\n\t\t\t\t" . $str_crontab . "\n\t\t\tLIMIT 1\n\t\t";
$db_result_agents = $DB->Query($strSql);
if ($db_result_agents->Fetch()) {
$db_lock = $DB->Query("SELECT GET_LOCK('" . $uniq . "_agent', 0) as L");
$ar_lock = $db_lock->Fetch();
if ($ar_lock["L"] == "0") {
return "";
}
} else {
if (CACHED_b_agent !== false) {
$rs = $DB->Query("SELECT UNIX_TIMESTAMP(MIN(NEXT_EXEC))-UNIX_TIMESTAMP(NOW()) DATE_DIFF FROM b_agent WHERE ACTIVE='Y' " . $str_crontab . "");
$ar = $rs->Fetch();
if (!$ar || $ar["DATE_DIFF"] < 0) {
$date_diff = 0;
} elseif ($ar["DATE_DIFF"] > CACHED_b_agent) {
$date_diff = CACHED_b_agent;
} else {
$date_diff = $ar["DATE_DIFF"];
}
if ($saved_time > 0) {
$CACHE_MANAGER->Clean($cache_id, "agents");
$CACHE_MANAGER->Read(CACHED_b_agent, $cache_id, "agents");
}
$CACHE_MANAGER->Set($cache_id, intval(time() + $date_diff));
}
return "";
}
$strSql = "SELECT ID, NAME, AGENT_INTERVAL, IS_PERIOD, MODULE_ID " . "FROM b_agent " . "WHERE ACTIVE='Y' " . "\tAND NEXT_EXEC<=now() " . "\tAND (DATE_CHECK IS NULL OR DATE_CHECK<=now()) " . $str_crontab . " ORDER BY RUNNING ASC, SORT desc";
$db_result_agents = $DB->Query($strSql);
$ids = '';
$agents_array = array();
while ($db_result_agents_array = $db_result_agents->Fetch()) {
$agents_array[] = $db_result_agents_array;
$ids .= ($ids != '' ? ', ' : '') . $db_result_agents_array["ID"];
}
if ($ids != '') {
$strSql = "UPDATE b_agent SET DATE_CHECK=DATE_ADD(IF(DATE_CHECK IS NULL, now(), DATE_CHECK), INTERVAL 600 SECOND) WHERE ID IN (" . $ids . ")";
$DB->Query($strSql);
}
$DB->Query("SELECT RELEASE_LOCK('" . $uniq . "_agent')");
$logFunction = defined("BX_AGENTS_LOG_FUNCTION") && function_exists(BX_AGENTS_LOG_FUNCTION) ? BX_AGENTS_LOG_FUNCTION : false;
for ($i = 0, $n = count($agents_array); $i < $n; $i++) {
$arAgent = $agents_array[$i];
if ($logFunction) {
$logFunction($arAgent, "start");
}
@set_time_limit(0);
ignore_user_abort(true);
if (strlen($arAgent["MODULE_ID"]) > 0 && $arAgent["MODULE_ID"] != "main") {
if (!CModule::IncludeModule($arAgent["MODULE_ID"])) {
continue;
}
}
//update the agent to the running state - if it fails it'll go to the end of the list on the next try
$DB->Query("UPDATE b_agent SET RUNNING='Y' WHERE ID=" . $arAgent["ID"]);
//these vars can be assigned within agent code
$pPERIOD = $arAgent["AGENT_INTERVAL"];
CTimeZone::Disable();
global $USER;
unset($USER);
$eval_result = "";
$e = eval("\$eval_result=" . $arAgent["NAME"]);
unset($USER);
CTimeZone::Enable();
if ($logFunction) {
$logFunction($arAgent, "finish", $eval_result, $e);
}
if ($e === false) {
continue;
} elseif (strlen($eval_result) <= 0) {
$strSql = "DELETE FROM b_agent WHERE ID=" . $arAgent["ID"];
} else {
$strSql = "\n\t\t\t\t\tUPDATE b_agent SET\n\t\t\t\t\t\tNAME='" . $DB->ForSQL($eval_result, 2000) . "',\n\t\t\t\t\t\tLAST_EXEC=now(),\n\t\t\t\t\t\tNEXT_EXEC=DATE_ADD(" . ($arAgent["IS_PERIOD"] == "Y" ? "NEXT_EXEC" : "now()") . ", INTERVAL " . $pPERIOD . " SECOND),\n\t\t\t\t\t\tDATE_CHECK=NULL,\n\t\t\t\t\t\tRUNNING='N'\n\t\t\t\t\tWHERE ID=" . $arAgent["ID"];
}
$DB->Query($strSql);
}
return null;
}
示例4: define
* @global CDatabase $DB
*/
define("START_EXEC_EPILOG_AFTER_1", microtime());
$GLOBALS["BX_STATE"] = "EA";
global $USER, $APPLICATION, $DB;
foreach (GetModuleEvents("main", "OnEpilog", true) as $arEvent) {
ExecuteModuleEventEx($arEvent);
}
$r = $APPLICATION->EndBufferContentMan();
$main_exec_time = round(getmicrotime() - START_EXEC_TIME, 4);
echo $r;
$arAllEvents = GetModuleEvents("main", "OnAfterEpilog", true);
define("START_EXEC_EVENTS_1", microtime());
$GLOBALS["BX_STATE"] = "EV";
CMain::EpilogActions();
define("START_EXEC_EVENTS_2", microtime());
$GLOBALS["BX_STATE"] = "EA";
foreach ($arAllEvents as $arEvent) {
ExecuteModuleEventEx($arEvent);
}
if (!IsModuleInstalled("compression") && !defined("ADMIN_AJAX_MODE") && $_REQUEST["mode"] != 'excel') {
$bShowTime = $_SESSION["SESS_SHOW_TIME_EXEC"] == 'Y';
$bShowStat = $DB->ShowSqlStat && $USER->CanDoOperation('edit_php');
$bShowCacheStat = \Bitrix\Main\Data\Cache::getShowCacheStat() && ($canEditPHP || $_SESSION["SHOW_CACHE_STAT"] == "Y");
if ($bShowTime || $bShowStat || $bShowCacheStat) {
include_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/interface/debug_info.php";
}
}
$DB->Disconnect();
CMain::ForkActions();
示例5: executeEvents
/**
* @return string
* @throws \Bitrix\Main\ArgumentException
* @throws \Bitrix\Main\ArgumentNullException
* @throws \Bitrix\Main\ArgumentTypeException
*/
public static function executeEvents()
{
$manage_cache = \Bitrix\Main\Application::getInstance()->getManagedCache();
if (defined("BX_FORK_AGENTS_AND_EVENTS_FUNCTION")) {
if (\CMain::ForkActions(array("CEvent", "ExecuteEvents"))) {
return "";
}
}
$bulk = intval(Config\Option::get("main", "mail_event_bulk", 5));
if ($bulk <= 0) {
$bulk = 5;
}
$connection = \Bitrix\Main\Application::getConnection();
if ($connection instanceof \Bitrix\Main\DB\MysqlCommonConnection) {
$uniq = Config\Option::get("main", "server_uniq_id", "");
if (strlen($uniq) <= 0) {
$uniq = md5(uniqid(rand(), true));
Config\Option::set("main", "server_uniq_id", $uniq);
}
$strSql = "SELECT 'x' FROM b_event WHERE SUCCESS_EXEC='N' LIMIT 1";
$resultEventDb = $connection->query($strSql);
if ($resultEventDb->fetch()) {
$lockDb = $connection->query("SELECT GET_LOCK('" . $uniq . "_event', 0) as L");
$arLock = $lockDb->fetch();
if ($arLock["L"] == "0") {
return "";
}
} else {
if (CACHED_b_event !== false) {
$manage_cache->set("events", true);
}
return "";
}
$strSql = "\n\t\t\t\tSELECT ID, C_FIELDS, EVENT_NAME, MESSAGE_ID, LID, DATE_FORMAT(DATE_INSERT, '%d.%m.%Y %H:%i:%s') as DATE_INSERT, DUPLICATE\n\t\t\t\tFROM b_event\n\t\t\t\tWHERE SUCCESS_EXEC='N'\n\t\t\t\tORDER BY ID\n\t\t\t\tLIMIT " . $bulk;
$rsMails = $connection->query($strSql);
} elseif ($connection instanceof \Bitrix\Main\DB\MssqlConnection) {
$connection->startTransaction();
$connection->query("SET LOCK_TIMEOUT 0");
\CTimeZone::Disable();
$strSql = "\n\t\t\t\tSELECT TOP " . $bulk . "\n\t\t\t\t\tID,\n\t\t\t\t\tC_FIELDS,\n\t\t\t\t\tEVENT_NAME,\n\t\t\t\t\tMESSAGE_ID,\n\t\t\t\t\tLID,\n\t\t\t\t\t" . $connection->getSqlHelper()->getDateToCharFunction("DATE_INSERT") . " as DATE_INSERT,\n\t\t\t\t\tDUPLICATE\n\t\t\t\tFROM b_event\n\t\t\t\tWITH (TABLOCKX)\n\t\t\t\tWHERE SUCCESS_EXEC = 'N'\n\t\t\t\tORDER BY ID\n\t\t\t\t";
$rsMails = $connection->query($strSql);
\CTimeZone::Enable();
} elseif ($connection instanceof \Bitrix\Main\DB\OracleConnection) {
$connection->startTransaction();
$strSql = "\n\t\t\t\tSELECT /*+RULE*/ E.ID, E.C_FIELDS, E.EVENT_NAME, E.MESSAGE_ID, E.LID,\n\t\t\t\t\tTO_CHAR(E.DATE_INSERT, 'DD.MM.YYYY HH24:MI:SS') as DATE_INSERT, DUPLICATE\n\t\t\t\tFROM b_event E\n\t\t\t\tWHERE E.SUCCESS_EXEC='N'\n\t\t\t\tORDER BY E.ID\n\t\t\t\tFOR UPDATE NOWAIT\n\t\t\t\t";
$rsMails = $connection->query($strSql);
}
if ($rsMails) {
$arCallableModificator = array();
$cnt = 0;
foreach (EventTable::getFetchModificatorsForFieldsField() as $callableModificator) {
if (is_callable($callableModificator)) {
$arCallableModificator[] = $callableModificator;
}
}
while ($arMail = $rsMails->fetch()) {
foreach ($arCallableModificator as $callableModificator) {
$arMail['C_FIELDS'] = call_user_func_array($callableModificator, array($arMail['C_FIELDS']));
}
$arFiles = array();
$fileListDb = EventAttachmentTable::getList(array('select' => array('FILE_ID'), 'filter' => array('EVENT_ID' => $arMail["ID"])));
while ($file = $fileListDb->fetch()) {
$arFiles[] = $file['FILE_ID'];
}
$arMail['FILE'] = $arFiles;
if (!is_array($arMail['C_FIELDS'])) {
$arMail['C_FIELDS'] = array();
}
$flag = Event::handleEvent($arMail);
EventTable::update($arMail["ID"], array('SUCCESS_EXEC' => $flag, 'DATE_EXEC' => new Type\DateTime()));
$cnt++;
if ($cnt >= $bulk) {
break;
}
}
}
if ($connection instanceof \Bitrix\Main\DB\MysqlCommonConnection) {
$connection->query("SELECT RELEASE_LOCK('" . $uniq . "_event')");
} elseif ($connection instanceof \Bitrix\Main\DB\MssqlConnection) {
$connection->query("SET LOCK_TIMEOUT -1");
$connection->commitTransaction();
} elseif ($connection instanceof \Bitrix\Main\DB\OracleConnection) {
$connection->commitTransaction();
}
if ($cnt === 0 && CACHED_b_event !== false) {
$manage_cache->set("events", true);
}
}
示例6: ExecuteAgents
public static function ExecuteAgents($str_crontab)
{
global $DB, $CACHE_MANAGER;
if (defined("BX_FORK_AGENTS_AND_EVENTS_FUNCTION")) {
if (CMain::ForkActions(array("CAgent", "ExecuteAgents"), array($str_crontab))) {
return "";
}
}
$saved_time = 0;
$cache_id = "agents" . $str_crontab;
if (CACHED_b_agent !== false && $CACHE_MANAGER->Read(CACHED_b_agent, $cache_id, "agents")) {
$saved_time = $CACHE_MANAGER->Get($cache_id);
if (time() < $saved_time) {
return "";
}
}
$uniq = COption::GetOptionString("main", "server_uniq_id", "");
if (strlen($uniq) <= 0) {
$uniq = md5(uniqid(rand(), true));
COption::SetOptionString("main", "server_uniq_id", $uniq);
}
$strSql = "\n\t\t\tSELECT 'x'\n\t\t\tFROM b_agent\n\t\t\tWHERE\n\t\t\t\tACTIVE = 'Y'\n\t\t\t\tAND NEXT_EXEC <= now()\n\t\t\t\tAND (DATE_CHECK IS NULL OR DATE_CHECK <= now())\n\t\t\t\t" . $str_crontab . "\n\t\t\tLIMIT 1\n\t\t";
$db_result_agents = $DB->Query($strSql);
if ($db_result_agents->Fetch()) {
$db_lock = $DB->Query("SELECT GET_LOCK('" . $uniq . "_agent', 0) as L");
$ar_lock = $db_lock->Fetch();
if ($ar_lock["L"] == "0") {
return "";
}
} else {
if (CACHED_b_agent !== false) {
$rs = $DB->Query("SELECT UNIX_TIMESTAMP(MIN(NEXT_EXEC))-UNIX_TIMESTAMP(NOW()) DATE_DIFF FROM b_agent WHERE ACTIVE='Y' " . $str_crontab . "");
$ar = $rs->Fetch();
if (!$ar || $ar["DATE_DIFF"] < 0) {
$date_diff = 0;
} elseif ($ar["DATE_DIFF"] > CACHED_b_agent) {
$date_diff = CACHED_b_agent;
} else {
$date_diff = $ar["DATE_DIFF"];
}
if ($saved_time > 0) {
$CACHE_MANAGER->Clean($cache_id, "agents");
$CACHE_MANAGER->Read(CACHED_b_agent, $cache_id, "agents");
}
$CACHE_MANAGER->Set($cache_id, intval(time() + $date_diff));
}
return "";
}
$strSql = "SELECT ID, NAME, AGENT_INTERVAL, IS_PERIOD, MODULE_ID " . "FROM b_agent " . "WHERE ACTIVE='Y' " . "\tAND NEXT_EXEC<=now() " . "\tAND (DATE_CHECK IS NULL OR DATE_CHECK<=now()) " . $str_crontab . " ORDER BY SORT desc";
$db_result_agents = $DB->Query($strSql);
$i = 0;
$ids = '';
$agents_array = array();
while ($db_result_agents_array = $db_result_agents->Fetch()) {
if ($i == 0) {
@set_time_limit(0);
ignore_user_abort(true);
$i = 1;
}
$agents_array[] = $db_result_agents_array;
$ids .= ($ids != '' ? ', ' : '') . $db_result_agents_array["ID"];
}
if ($ids != '') {
$strSql = "UPDATE b_agent SET DATE_CHECK=DATE_ADD(IF(DATE_CHECK IS NULL, now(), DATE_CHECK), INTERVAL 600 SECOND) WHERE ID IN (" . $ids . ")";
$DB->Query($strSql);
}
$DB->Query("SELECT RELEASE_LOCK('" . $uniq . "_agent')");
for ($i = 0, $n = count($agents_array); $i < $n; $i++) {
$arAgent = $agents_array[$i];
@set_time_limit(0);
if (strlen($arAgent["MODULE_ID"]) > 0 && $arAgent["MODULE_ID"] != "main") {
if (!CModule::IncludeModule($arAgent["MODULE_ID"])) {
continue;
}
}
//these vars can be assigned within agent code
$pPERIOD = $arAgent["AGENT_INTERVAL"];
CTimeZone::Disable();
global $USER;
unset($USER);
$eval_result = "";
eval("\$eval_result=" . $arAgent["NAME"]);
unset($USER);
CTimeZone::Enable();
if (strlen($eval_result) <= 0) {
$strSql = "DELETE FROM b_agent WHERE ID=" . $arAgent["ID"];
} else {
if ($arAgent["IS_PERIOD"] == "Y") {
$strSql = "UPDATE b_agent SET NAME='" . $DB->ForSQL($eval_result, 2000) . "', LAST_EXEC=now(), NEXT_EXEC=DATE_ADD(NEXT_EXEC, INTERVAL " . $pPERIOD . " SECOND), DATE_CHECK=NULL WHERE ID=" . $arAgent["ID"];
} else {
$strSql = "UPDATE b_agent SET NAME='" . $DB->ForSQL($eval_result, 2000) . "', LAST_EXEC=now(), NEXT_EXEC=DATE_ADD(now(), INTERVAL " . $pPERIOD . " SECOND), DATE_CHECK=NULL WHERE ID=" . $arAgent["ID"];
}
}
$DB->Query($strSql);
}
return null;
}
示例7: LocalRedirect
function LocalRedirect($url, $skip_security_check = false, $status = "302 Found")
{
/** @global CMain $APPLICATION */
global $APPLICATION;
/** @global CDatabase $DB */
global $DB;
/*if(defined("DEMO") && DEMO=="Y" && (!defined("SITEEXPIREDATE") || !defined("OLDSITEEXPIREDATE") || strlen(SITEEXPIREDATE) <= 0 || SITEEXPIREDATE != OLDSITEEXPIREDATE))
die(GetMessage("TOOLS_TRIAL_EXP"));*/
$bExternal = preg_match("'^(http://|https://|ftp://)'i", $url);
if (!$bExternal && strpos($url, "/") !== 0) {
$url = $APPLICATION->GetCurDir() . $url;
}
//doubtful
$url = str_replace("&", "&", $url);
// http response splitting defence
$url = str_replace(array("\r", "\n"), "", $url);
if (!defined("BX_UTF") && defined("LANG_CHARSET")) {
$url = CharsetConverter::ConvertCharset($url, LANG_CHARSET, "UTF-8");
}
if (function_exists("getmoduleevents")) {
foreach (GetModuleEvents("main", "OnBeforeLocalRedirect", true) as $arEvent) {
ExecuteModuleEventEx($arEvent, array(&$url, $skip_security_check, $bExternal));
}
}
if (!$bExternal) {
//store cookies for next hit (see CMain::GetSpreadCookieHTML())
$APPLICATION->StoreCookies();
$host = $_SERVER['HTTP_HOST'];
if ($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443 && $_SERVER['SERVER_PORT'] > 0 && strpos($_SERVER['HTTP_HOST'], ":") === false) {
$host .= ":" . $_SERVER['SERVER_PORT'];
}
$protocol = CMain::IsHTTPS() ? "https" : "http";
$url = $protocol . "://" . $host . $url;
}
CHTTP::SetStatus($status);
header("Location: " . $url);
if (function_exists("getmoduleevents")) {
foreach (GetModuleEvents("main", "OnLocalRedirect", true) as $arEvent) {
ExecuteModuleEventEx($arEvent);
}
}
$_SESSION["BX_REDIRECT_TIME"] = time();
CMain::ForkActions();
exit;
}