public static function AddByChannel($channelId, $arMessage) { global $DB; if (strlen($arMessage['module_id'])<=0 || strlen($arMessage['command'])<=0) return false; $arData = Array( 'module_id' => $arMessage['module_id'], 'command' => $arMessage['command'], 'params' => is_array($arMessage['params'])?$arMessage['params']: Array(), ); if (CPullOptions::GetNginxStatus()) { $message = CUtil::PhpToJsObject(Array('CHANNEL_ID' => $channelId, 'MESSAGE' => Array($arData), 'ERROR' => '')); if (!defined('BX_UTF') || !BX_UTF) $message = $GLOBALS['APPLICATION']->ConvertCharset($message, SITE_CHARSET,'utf-8'); $CHTTP = new CHTTP(); $CHTTP->http_timeout = 10; if ($CHTTP->HTTPQuery('POST', CPullOptions::GetPublishUrl($channelId), str_replace("\n", " ", $message))) $result = $CHTTP->result; } else { $arParams = Array( 'CHANNEL_ID' => $channelId, 'MESSAGE' => str_replace("\n", " ", serialize($arData)), '~DATE_CREATE' => $DB->CurrentTimeFunction(), ); $id = IntVal($DB->Add("b_pull_stack", $arParams, Array("MESSAGE"))); $result = $id? '{"channel": "'.$channelId.'", "id": "'.$id.'"}': false; } if (isset($arMessage['push_text']) && strlen($arMessage['push_text'])>0 && isset($arMessage['push_user']) && intval($arMessage['push_user'])>0) { $CPushManager = new CPushManager(); $CPushManager->AddQueue(Array( 'USER_ID' => $arMessage['push_user'], 'MESSAGE' => str_replace("\n", " ", $arMessage['push_text']), 'PARAMS' => $arMessage['push_params'], 'TAG' => isset($arMessage['push_tag'])? $arMessage['push_tag']: '', )); } return $result; }
/** * Return some information about P&P, such as publish url * * @since 14.5.4 * @return array */ protected static function getPullingInfo() { $result = array('enabled' => CModule::IncludeModule('pull') && CPullOptions::ModuleEnable()); if ($result['enabled']) { $result['nginx_used'] = CPullOptions::GetQueueServerStatus(); if ($result['nginx_used']) { $result['server_protocol'] = CPullOptions::GetQueueServerVersion(); $result['publish_url'] = CPullOptions::GetPublishUrl(); $result['pulling_url'] = CPullOptions::GetListenUrl(); $result['pulling_url_secure'] = CPullOptions::GetListenSecureUrl(); $result['websocket_url'] = CPullOptions::GetWebSocketUrl(); $result['websocket_url_secure'] = CPullOptions::GetWebSocketSecureUrl(); } } return $result; }
public static function Add($userId) { global $DB, $APPLICATION; $channelId = md5(uniqid() . $_SERVER["REMOTE_ADDR"] . $_SERVER["SERVER_NAME"] . (is_object($APPLICATION) ? $APPLICATION->GetServerUniqID() : '')); $arParams = array('USER_ID' => intval($userId), 'CHANNEL_ID' => $channelId, 'LAST_ID' => 0, '~DATE_CREATE' => $DB->CurrentTimeFunction()); $result = IntVal($DB->Add("b_pull_channel", $arParams, array())); if (CPullOptions::GetNginxStatus()) { $result = false; $arData = array('module_id' => 'pull', 'command' => 'open', 'params' => array()); $CHTTP = new CHTTP(); $CHTTP->http_timeout = 10; if ($CHTTP->HTTPQuery('POST', CPullOptions::GetPublishUrl($channelId), CUtil::PhpToJsObject(array('MESSAGE' => array($arData), 'ERROR' => '')))) { $result = $CHTTP->result; } } return $result ? $channelId : false; }
public static function AddByChannel($channelId, $arMessage) { global $DB; if (strlen($arMessage['module_id']) <= 0 || strlen($arMessage['command']) <= 0) { return false; } $arData = array('module_id' => $arMessage['module_id'], 'command' => $arMessage['command'], 'params' => is_array($arMessage['params']) ? $arMessage['params'] : array()); if (CPullOptions::GetNginxStatus()) { $CHTTP = new CHTTP(); $CHTTP->http_timeout = 10; if ($CHTTP->HTTPQuery('POST', CPullOptions::GetPublishUrl($channelId), str_replace("\n", " ", CUtil::PhpToJsObject(array('CHANNEL_ID' => $channelId, 'MESSAGE' => array($arData), 'ERROR' => ''))))) { $result = $CHTTP->result; } } else { $arParams = array('CHANNEL_ID' => $channelId, 'MESSAGE' => str_replace("\n", " ", serialize($arData)), '~DATE_CREATE' => $DB->CurrentTimeFunction()); $id = IntVal($DB->Add("b_pull_stack", $arParams, array("MESSAGE"))); $result = $id ? '{"channel": "' . $channelId . '", "id": "' . $id . '"}' : false; } if (isset($arMessage['push_text']) && strlen($arMessage['push_text']) > 0 && isset($arMessage['push_user']) && intval($arMessage['push_user']) > 0) { $CPushManager = new CPushManager(); $CPushManager->AddQueue(array('USER_ID' => $arMessage['push_user'], 'MESSAGE' => str_replace("\n", " ", $arMessage['push_text']), 'PARAMS' => $arMessage['push_params'], 'TAG' => isset($arMessage['push_tag']) ? $arMessage['push_tag'] : '')); } return $result; }
private static function SendCommand($channelId, $message, $method = 'POST', $timeout = 5, $dont_wait_answer = true) { if (!is_array($channelId)) $channelId = Array($channelId); $channelId = implode('/', array_unique($channelId)); if (strlen($channelId) <=0 || strlen($message) <= 0) return false; if (!in_array($method, Array('POST', 'GET'))) return false; $nginx_error = COption::GetOptionString("pull", "nginx_error", "N"); if ($nginx_error != "N") { $nginx_error = unserialize($nginx_error); if (intval($nginx_error['date'])+120 < time()) { COption::SetOptionString("pull", "nginx_error", "N"); CAdminNotify::DeleteByTag("PULL_ERROR_SEND"); $nginx_error = "N"; } else if ($nginx_error['count'] >= 10) { $ar = Array( "MESSAGE" => GetMessage('PULL_ERROR_SEND'), "TAG" => "PULL_ERROR_SEND", "MODULE_ID" => "pull", ); CAdminNotify::Add($ar); return false; } } $postdata = CHTTP::PrepareData($message); $CHTTP = new CHTTP(); $CHTTP->http_timeout = intval($timeout); $arUrl = $CHTTP->ParseURL(CPullOptions::GetPublishUrl($channelId), false); if ($CHTTP->Query($method, $arUrl['host'], $arUrl['port'], $arUrl['path_query'], $postdata, $arUrl['proto'], 'N', $dont_wait_answer)) { $result = $dont_wait_answer? '{}': $CHTTP->result; } else { if ($nginx_error == "N") { $nginx_error = Array( 'count' => 1, 'date' => time(), 'date_increment' => time(), ); } else if (intval($nginx_error['date_increment'])+1 < time()) { $nginx_error['count'] = intval($nginx_error['count'])+1; $nginx_error['date_increment'] = time(); } COption::SetOptionString("pull", "nginx_error", serialize($nginx_error)); $result = false; } return $result; }
<tr> <td width="40%"><?=GetMessage("PULL_OPTIONS_USE")?>:</td> <td width="60%"><?=implode(", ", $arDependentModule)?></td> </tr> <?endif;?> <tr> <td width="40%"></td> <td width="60%"></td> </tr> <tr> <td width="40%"><nobr><?=GetMessage("PULL_OPTIONS_NGINX")?></nobr>:</td> <td width="60%"><input id="config_nginx" type="checkbox" size="40" value="Y" <?=(CPullOptions::GetNginxStatus()?' checked':'')?> name="nginx"></td> </tr> <tr> <td><?=GetMessage("PULL_OPTIONS_PATH_TO_PUBLISH")?>:</td> <td><input id="config_path_to_publish" type="text" size="40" value="<?=htmlspecialcharsbx(CPullOptions::GetPublishUrl())?>" name="path_to_publish" <?=(CPullOptions::GetNginxStatus()? '':'disabled="true"')?>></td> </tr> <tr> <td ><?=GetMessage("PULL_OPTIONS_PATH_TO_LISTENER")?>:</td> <td><input id="config_path_to_listener" type="text" size="40" value="<?=htmlspecialcharsbx(CPullOptions::GetListenUrl())?>" name="path_to_listener" <?=(CPullOptions::GetNginxStatus()? '':'disabled="true"')?>></td> </tr> <?/* <tr> <td width="40%"><nobr><?=GetMessage("PULL_OPTIONS_WEBSOCKET")?></nobr>:</td> <td width="60%"><input id="config_websocket" type="checkbox" size="40" value="Y" <?=(CPullOptions::GetWebSocketStatus()?' checked':'')?> name="websocket" <?=(CPullOptions::GetNginxStatus()? '':'disabled="true"')?>></td> </tr> <tr> <td ><?=GetMessage("PULL_OPTIONS_PATH_TO_WEBSOCKET")?>:</td> <td><input id="config_path_to_websocket" type="text" size="40" value="<?=htmlspecialcharsbx(CPullOptions::GetWebSocketUrl())?>" name="path_to_websocket" <?=(!CPullOptions::GetNginxStatus() || !CPullOptions::GetWebSocketStatus() ? 'disabled="true"': '')?></td> </tr> */?>
private static function SendCommand($channelId, $message, $options = array()) { if (!is_array($channelId)) { $channelId = array($channelId); } $channelId = implode('/', array_unique($channelId)); if (strlen($channelId) <= 0 || strlen($message) <= 0) { return false; } $defaultOptions = array("method" => "POST", "timeout" => 5, "dont_wait_answer" => true); $options = array_merge($defaultOptions, $options); if (!in_array($options["method"], array('POST', 'GET'))) { return false; } $nginx_error = COption::GetOptionString("pull", "nginx_error", "N"); if ($nginx_error != "N") { $nginx_error = unserialize($nginx_error); if (intval($nginx_error['date']) + 120 < time()) { COption::SetOptionString("pull", "nginx_error", "N"); CAdminNotify::DeleteByTag("PULL_ERROR_SEND"); $nginx_error = "N"; } else { if ($nginx_error['count'] >= 10) { $ar = array("MESSAGE" => GetMessage('PULL_ERROR_SEND'), "TAG" => "PULL_ERROR_SEND", "MODULE_ID" => "pull"); CAdminNotify::Add($ar); return false; } } } $postdata = CHTTP::PrepareData($message); $CHTTP = new CHTTP(); $CHTTP->http_timeout = intval($options["timeout"]); if (isset($options["expiry"])) { $CHTTP->SetAdditionalHeaders(array("Message-Expiry" => intval($options["expiry"]))); } $arUrl = $CHTTP->ParseURL(CPullOptions::GetPublishUrl($channelId), false); try { $sendResult = $CHTTP->Query($options["method"], $arUrl['host'], $arUrl['port'], $arUrl['path_query'], $postdata, $arUrl['proto'], 'N', $options["dont_wait_answer"]); } catch (Exception $e) { $sendResult = false; } if ($sendResult) { $result = $options["dont_wait_answer"] ? '{}' : $CHTTP->result; } else { if ($nginx_error == "N") { $nginx_error = array('count' => 1, 'date' => time(), 'date_increment' => time()); } else { if (intval($nginx_error['date_increment']) + 1 < time()) { $nginx_error['count'] = intval($nginx_error['count']) + 1; $nginx_error['date_increment'] = time(); } } COption::SetOptionString("pull", "nginx_error", serialize($nginx_error)); $result = false; } return $result; }
?> </td> </tr> <tr class="heading"> <td colspan="2"><b><?php echo GetMessage('PULL_OPTIONS_HEAD_PUB'); ?> </b></td> </tr> <tr> <td><?php echo GetMessage("PULL_OPTIONS_PATH_TO_PUBLISH"); ?> :</td> <td><input id="config_path_to_publish" type="text" size="40" value="<?php echo htmlspecialcharsbx(CPullOptions::GetPublishUrl()); ?> " name="path_to_publish" <?php echo CPullOptions::GetQueueServerStatus() ? '' : 'disabled="true"'; ?> ></td> </tr> <tr> <td align="right" width="50%"><?php echo GetMessage("PULL_OPTIONS_NGINX_BUFFER"); ?> :</td> <td><input id="config_nginx_command_per_hit" type="text" size="10" value="<?php echo CPullOptions::GetCommandPerHit(); ?> " name="nginx_command_per_hit" <?php
:</td> <td><input id="config_path_to_listener" type="text" size="40" value="<?php echo CPullOptions::GetListenUrl(); ?> " name="path_to_listener" <?php echo CPullOptions::GetNginxStatus() ? '' : 'disabled="true"'; ?> ></td> </tr> <tr> <td><?php echo GetMessage("PULL_OPTIONS_PATH_TO_PUBLISH"); ?> :</td> <td><input id="config_path_to_publish" type="text" size="40" value="<?php echo CPullOptions::GetPublishUrl(); ?> " name="path_to_publish" <?php echo CPullOptions::GetNginxStatus() ? '' : 'disabled="true"'; ?> ></td> </tr> <?php if (IsModuleInstalled('mobileapp')) { ?> <tr> <td align="right" width="50%"><?php echo GetMessage("PULL_OPTIONS_PUSH"); ?> :</td> <td><input type="checkbox" size="40" value="Y" <?php