我正在为我的应用程序而苦苦挣扎。我有几个 php 函数导致我出现 503 错误。我正在使用 Nette 框架。
第一个函数通过连接到 Mysql 并将 Mysql 条目与常量相乘来获得“商品生产”的数量。我对此没有任何问题。
public function GetCommodityProduction($estId, $commodity)
{
switch ($commodity)
{
case 'money':
$cityCount = $this->database->table('buildings')->where('id = ?', $estId)->fetch()->city;
$commodityProduction = ($cityCount * self::CITY_PRODUCTION);
return round($commodityProduction);
break;
case 'resources':
$mineCount = $this->database->table('buildings')->where('id = ?', $estId)->fetch()->mine;
$commodityProduction = ($mineCount * self::MINE_PRODUCTION);
return round($commodityProduction);
break;
case 'energy':
........
}
}
第二个函数使用该商品的方式与我获得商品生产的方式相同:
public function GetCommodityUsage($estId, $commodity)
{
switch ($commodity)
{
case 'money':
$barracksCount = $this->database->table('buildings')->where('id = ?', $estId)->fetch()->barracks;
$tankCount = $this->database->table('army')->where('id = ?', $estId)->fetch()->tank;
$commodityUsage = (($barracksCount * self::BARRACKS_MONEY_CONSUMPTION) +
($tankCount * self::TANK_MONEY_CONSUMPTION));
return round($commodityUsage);
break;
case 'resources':
$tankProduction = $this->factoryProduction->getFactoryProduction($estId, 'tank');
$commodityUsage = (($tankProduction * self::TANK_RESOURCES_CONSUMPTION));
return round($commodityUsage);
break;
case 'energy':
..........
}
}
当我尝试在这个函数中减去这两个函数的值时,问题就开始了:
public function GetActualCommodityProduction($estId, $commodity)
{
switch ($commodity)
{
case 'money':
$actualProduction = $this->GetActualCommodityProduction($estId, 'money') -
$this->GetCommodityUsage($estId, 'money');
return round($actualProduction);
break;
case 'resources':
$actualProduction = $this->GetActualCommodityProduction($estId, 'resources') -
$this->GetCommodityUsage($estId, 'resources');
return round($actualProduction);
break;
case 'energy':
.......
}
}
我认为问题在于最后一个功能是服务器超载。但我不确定。您能告诉我如何修改这些功能以使其正常工作吗?