Разработал свой игровой мод для сервера PocketMine (Minecraft) На PHP 7.2. Данный код нагружает мой проект значительно, данные действия производятся каждый раз когда игрок отправляет сообщение в чат.
if(empty($this->timeOutPlayersIssues[$p->getName()])){
//..Пропускаем сообщение
$time = time()+$tiiime;
$this->timeOutPlayersIssues[$p->getName()] = $time;
} elseif($this->timeOutPlayersIssues[$p->getName()] <= time()){
$time = time()+$tiiime;
$this->timeOutPlayersIssues[$p->getName()] = $time;
} else{
$time = $this->timeOutPlayersIssues[$p->getName()] - time();
$p->sendMessage("§8[§cЧат§8] §eНе флуди! Подожди ещё §a{$time} §eсекунд, чтобы отправить сообщение.");
$e->setCancelled(true);
}
if(@$this->mutedPlayers[$p->getName()]) {
$e->setCancelled(true);
$p->sendMessage("§8[§cМенеджер Мутов§8] §eТы был замучен до рестарта!");
}
$groupName=$this->api->getUserDataMgr()->getGroup($p)->getName();
// Local & Global Chat
$getConfigPrefix = $this->prefixes->get($groupName);
if($msg{0}=="!") {
str_replace("!", "", $msg{0});
$global = true;
} else {
$global = false;
}
$formatLocal = $this->prefixes->get('MS_PEManagerChatFormat__Local');
$formatGlobal = $this->prefixes->get('MS_PEManagerChatFormat__Global');
$donaterColor = $this->prefixes->get("цвет_{$groupName}");
$prefixFaction = $this->factionsPro->getPlayerFaction($p->getName());
if(!$prefixFaction) {
unset($prefixFaction);$prefixFaction = "§7Без клана§r";
}
// Получаем статус женат или нет из API marry
$marryStatus = $this->marry->isMarried(strtolower($p->getName()));
if($marryStatus) {
unset($marryStatus);
$marryStatus = $this->prefixes->get("marrySymbol");
}
if($p->isOp()){
$getConfigPrefix = "§4§o§l>>> §r§b§lОператор §4§l§o§<<<§r §b§l";
$donaterColor = "§4§l§o";
}
$mysqli = $this->databaseConnect();
$mysqli->set_charset("utf8");
$ac_ = strtolower($p->getName());
$getpref = $mysqli->Query("SELECT * FROM `MS_Prefixes_Users` WHERE `account` = '{$ac_}'");
if($getpref->num_rows == 1) {
while($prf = $getpref->fetch_assoc()){
$sql_prefix = $prf['prefix'];
$sql_color = $prf['color'];
}
} else {
$sql_prefix = false;
$sql_color = '§6';
}
if($mysqli->Query("SELECT * FROM `MS_LevelSystem` WHERE `name` = '{$p->getName()}' LIMIT 1")->num_rows == 1) {
$getLevel = $mysqli->Query("SELECT * FROM `MS_LevelSystem` WHERE `name` = '{$p->getName()}' LIMIT 1");
while($rr=$getLevel->fetch_assoc()){
$level = $rr['level'];
}
$formatLocal = str_replace('[levelSystem]',$level,$formatLocal);
$formatGlobal = str_replace('[levelSystem]',$level,$formatGlobal);
} else {
$formatLocal = str_replace('[levelSystem]',0,$formatLocal);
$formatGlobal = str_replace('[levelSystem]',0,$formatGlobal);
}
$formatLocal = str_replace('[marry]',$marryStatus,$formatLocal);
$formatLocal = str_replace('[clantag]',str_replace("&","§",$prefixFaction),$formatLocal);
if(!$sql_prefix) {
$formatLocal = str_replace('[prefix]',str_replace("&","§",$getConfigPrefix),$formatLocal);
} else {
$formatLocal = str_replace('[prefix]',str_replace("&","§",str_replace("&","§",'§r§8[§r'.$sql_prefix.'§r§8] ' . $sql_color)),$formatLocal);
}
$formatLocal = str_replace('[name]',str_replace("&","§",$p->getName()),$formatLocal);
$formatLocal = str_replace('[color]',$donaterColor,$formatLocal);
$formatLocal = str_replace('&',"§",$formatLocal);
if($p->hasPermission("mschat.color")) {
$formatLocal = str_replace('[message]',str_replace("&","§",$msg),$formatLocal);
$formatLocal = str_replace('[message]',str_replace("§","&",$msg),$formatLocal);
} else {
$formatLocal = str_replace('[message]',$msg,$formatLocal);
$formatLocal = str_replace('[message]',str_replace("§","",$msg),$formatLocal);
$formatLocal = str_replace('[message]',str_replace("&","",$msg),$formatLocal);
}
$formatGlobal = str_replace('[marry]',$marryStatus,$formatGlobal);
$formatGlobal = str_replace('[clantag]',str_replace("&","§",$prefixFaction),$formatGlobal);
if(!$sql_prefix) {
$formatGlobal = str_replace('[prefix]',str_replace("&","§",$getConfigPrefix),$formatGlobal);
} else {
$formatGlobal = str_replace('[prefix]',str_replace("&","§",str_replace("&","§",'§r§8[§r'.$sql_prefix.'§r§8] ' . $sql_color)),$formatGlobal);
}
$formatGlobal = str_replace('[name]',str_replace("&","§",$p->getName()),$formatGlobal);
$formatGlobal = str_replace('[color]',$donaterColor,$formatGlobal);
$formatGlobal = str_replace('&',"§",$formatGlobal);
if($p->hasPermission("mschat.color")) {
$formatGlobal = str_replace('[message]',str_replace("&","§",$msg),$formatGlobal);
$formatGlobal = str_replace('[message]',str_replace("§","&",$msg),$formatGlobal);
} else {
$formatGlobal = str_replace('[message]',$msg,$formatGlobal);
$formatGlobal = str_replace('[message]',str_replace("§","",$msg),$formatGlobal);
$formatGlobal = str_replace('[message]',str_replace("&","",$msg),$formatGlobal);
}
Особенно вызывает большой вопрос, каким образом можно заменить str_replace, чтобы повысить производительность?
Сборка персонального компьютера от Artline: умный выбор для современных пользователей