本文整理汇总了PHP中Protocol::encode方法的典型用法代码示例。如果您正苦于以下问题:PHP Protocol::encode方法的具体用法?PHP Protocol::encode怎么用?PHP Protocol::encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Protocol
的用法示例。
在下文中一共展示了Protocol::encode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: report
/**
* 上报统计数据
*
* @param string $module
* @param string $interface
* @param bool $success
* @param int $code
* @param string $msg
* @param string $report_address
* @return boolean
*/
public static function report($module, $interface, $success, $code, $msg, $report_address = '')
{
$report_address = $report_address ? $report_address : '127.0.0.1:55656';
if (isset(self::$timeMap[$module][$interface]) && self::$timeMap[$module][$interface] > 0) {
$time_start = self::$timeMap[$module][$interface];
self::$timeMap[$module][$interface] = 0;
} else {
if (isset(self::$timeMap['']['']) && self::$timeMap[''][''] > 0) {
$time_start = self::$timeMap[''][''];
self::$timeMap[''][''] = 0;
} else {
$time_start = microtime(true);
}
}
$cost_time = microtime(true) - $time_start;
$bin_data = Protocol::encode($module, $interface, $cost_time, $success, $code, $msg);
if (extension_loaded('swoole')) {
if (!self::$client || !self::$client->isConnected()) {
self::$client = new swoole_client(SWOOLE_TCP, SWOOLE_SOCK_SYNC);
list($ip, $port) = explode(':', $report_address);
self::$client->connect($ip, $port);
}
self::$client->send($bin_data);
self::$client->close();
self::$client = null;
} else {
return self::sendData($report_address, $bin_data);
}
}
示例2: getRetString
/**
* 获得返回字符串
*
* @param code 全局返回码
* @param results results值
*/
public static function getRetString($code, $results = null)
{
$msg = "未知错误,错误代码({$code})";
switch ($code) {
case 0:
$msg = "ok";
break;
case 1:
$msg = "错误";
break;
}
if ($results != null) {
return Protocol::encode(array("code" => $code, "msg" => $msg, "results" => $results));
} else {
return Protocol::encode(array("code" => $code, "msg" => $msg));
}
}
示例3: report
/**
* 上报统计数据
*
* @param string $module
* @param string $interface
* @param bool $success
* @param int $code
* @param string $msg
* @param string $report_address
* @return boolean
*/
public static function report($module, $interface, $success, $code, $msg, $report_address = '')
{
$report_address = $report_address ? $report_address : 'udp://127.0.0.1:55656';
if (isset(self::$timeMap[$module][$interface]) && self::$timeMap[$module][$interface] > 0) {
$time_start = self::$timeMap[$module][$interface];
self::$timeMap[$module][$interface] = 0;
} else {
if (isset(self::$timeMap['']['']) && self::$timeMap[''][''] > 0) {
$time_start = self::$timeMap[''][''];
self::$timeMap[''][''] = 0;
} else {
$time_start = microtime(true);
}
}
$cost_time = microtime(true) - $time_start;
$bin_data = Protocol::encode($module, $interface, $cost_time, $success, $code, $msg);
return self::sendData($report_address, $bin_data);
}