0

I made a script that gets data from my database then uses that data for each player in my databse to calculate there skill level and other parameters that are added to a array. Then from that array all data is entered into a table in my database for toplist.

Now my problem is it works on localhost with 0 errors but when i run it on my server it seems to only run to:

echo $calculatediamondgrade." + ".$calculatediamondgradeforamted." + ".$summonerData->name."<br>";

I am trying to get it to work and I dont see any problem with in my coding as when, could someone take a look and let me think your thoughts.

<?php
set_time_limit(0);

require_once 'connect_db.php';

$emptyQuery = "TRUNCATE top_list;";
if ($conn->query($emptyQuery)) {

    $sql = "SELECT summoner_info, tier_info, ranked_champs_info FROM players_data";
    $result = $conn->query($sql);
    if ($result->num_rows > 0) {

        $players = array();
        $champsPoints = array();

        while ($row = $result->fetch_assoc()) {
            $summonerData = unserialize($row['summoner_info']);
            $tierData = unserialize($row['tier_info']);
            if ($tierData == NULL || !isset($tierData)) {
                $tierData = new stdClass();
                $tierData->tier = 'UNRANKED';
                $tierEntry = new stdClass();
                $tierEntry->division = '';
            } else {
                $tierData = $tierData[0];
                $tierEntry = $tierData->entries[0];
            }

            $ranked_champs_infoData = unserialize($row['ranked_champs_info']);

            if ($row['summoner_info'] !== "N;") {
                if ($row['ranked_champs_info'] !== "N;") {
                    foreach ($ranked_champs_infoData->champions as $champData) {
                        $champIDs = $champData->id;

                        if (!$champIDs == 0) {
                            $totalsessionsplayedwithachampion = $champData->stats->totalSessionsPlayed;

                            if ($totalsessionsplayedwithachampion >= 10) {


                                $champstotalSessionsWon = $champData->stats->totalSessionsWon;
                                $champstotalSessionsLost = $champData->stats->totalSessionsLost;

                                $getMiniomskillsNamelistside = $champData->stats->totalMinionKills;
                                $KDAMinniomsSide = $getMiniomskillsNamelistside / ($totalsessionsplayedwithachampion);

                                if (isset($champData->stats) && isset($champData->stats->totalChampionKills)) {
                                    /* Champion total kills */
                                    $champsdatazkillz = $champData->stats->totalChampionKills;
                                } else {
                                    $champsdatazkillz = 0;
                                }

                                if (isset($champData->stats) && isset($champData->stats->totalAssists)) {
                                    /* Champion total assists */
                                    $champsdatazassitsz = $champData->stats->totalAssists;
                                } else {
                                    $champsdatazassitsz = 0;
                                }

                                if (isset($champData->stats) && isset($champData->stats->totalDeathsPerSession)) {
                                    /* Champion total deaths */
                                    $champsdatazdeathz = $champData->stats->totalDeathsPerSession;
                                } else {
                                    $champsdatazdeathz = 0;
                                }

                                if ($champsdatazdeathz == 0) {
                                    $KDAsidechamps = ($champsdatazkillz + $champsdatazassitsz);
                                } else {
                                    $KDAsidechamps = ($champsdatazkillz + $champsdatazassitsz) / $champsdatazdeathz;
                                }

                                if ($tierData->tier == "CHALLENGER") {
                                    $championrankMOD = '1.9';
                                    $championrankKDA = 0.95;
                                    $championrankKDAminniom = 0.0095;
                                } else if ($tierData->tier == "MASTER") {
                                    $championrankMOD = '1.85';
                                    $championrankKDA = 0.93;
                                    $championrankKDAminniom = 0.0093;
                                } else if ($tierData->tier == "DIAMOND") {
                                    $championrankMOD = '1.8';
                                    $championrankKDA = 0.9;
                                    $championrankKDAminniom = 0.0090;
                                } else if ($tierData->tier == "PLATINUM") {
                                    $championrankMOD = '1.7';
                                    $championrankKDA = 0.86;
                                    $championrankKDAminniom = 0.0087;
                                } else if ($tierData->tier == "GOLD") {
                                    $championrankMOD = '1.65';
                                    $championrankKDA = 0.82;
                                    $championrankKDAminniom = 0.0085;
                                } else if ($tierData->tier == "SILVER") {
                                    $championrankMOD = '1.55';
                                    $championrankKDA = 0.75;
                                    $championrankKDAminniom = 0.0083;
                                } else if ($tierData->tier == "BRONZE") {
                                    $championrankMOD = '1.45';
                                    $championrankKDA = 0.71;
                                    $championrankKDAminniom = 0.0080;
                                } else if ($tierData->tier == "UNRANKED") {
                                    $championrankMOD = '1.55';
                                    $championrankKDA = 0.75;
                                    $championrankKDAminniom = 0.0083;
                                }

                                $calculatediamondgrade = ((pow(number_format((float)$KDAsidechamps, 2, '.', ''), 1 / 2) * $championrankKDA) + (pow(number_format((float)$KDAMinniomsSide, 2, '.', ''), 1 / 20) * $championrankKDAminniom)) * pow((($champstotalSessionsWon + 0.5) / (($champstotalSessionsWon + 0.4) + ($champstotalSessionsLost + 0.3))), 1 / 1.1) * pow((($champstotalSessionsWon) + ($champstotalSessionsLost - 0.4)), 1 / 8) * $championrankMOD;

                                $calculatediamondgradeforamted = number_format((float)$calculatediamondgrade, 3, '.', '') * (1000);

                                echo $calculatediamondgrade . " + " . $calculatediamondgradeforamted . " + " . $summonerData->name . "<br>";

                                array_push($players, array(
                                    'champId' => $champData->id,
                                    'profileiconid' => $summonerData->profileIconId,
                                    'playerName' => $summonerData->name,
                                    'tier' => $tierData->tier,
                                    'division' => $tierEntry->division,
                                    'championPoints' => $calculatediamondgradeforamted,
                                    'gamesplayed' => $totalsessionsplayedwithachampion
                                ));
                                array_push($champsPoints, $calculatediamondgradeforamted);
                            }
                        }
                    }
                }
            }
        }

        rsort($champsPoints);

        usort($players, function ($a, $b) use ($champsPoints) {
            $pos_a = array_search($a['championPoints'], $champsPoints);
            $pos_b = array_search($b['championPoints'], $champsPoints);
            return $pos_a - $pos_b;
        });

        $championsPoints = array_values(array_unique($champsPoints));
        $playersByCP = array();

        foreach ($championsPoints as $champsPoint) {
            $sameCPs = array();
            foreach ($players as $player) {
                $sameCP = array();
                if ($player['championPoints'] == $champsPoint) {
                    switch ($player['tier']) {
                        case 'BRONZE':
                            switch ($player['division']) {
                                case 'I':
                                    $sameCP['tier'] = 'z5';
                                    break;
                                case 'II':
                                    $sameCP['tier'] = 'z4';
                                    break;
                                case 'III':
                                    $sameCP['tier'] = 'z3';
                                    break;
                                case 'IV':
                                    $sameCP['tier'] = 'z2';
                                    break;
                                case 'V':
                                    $sameCP['tier'] = 'z1';
                                    break;
                                default:
                                    $sameCP['tier'] = 'Error Bronze';
                                    break;
                            }
                            break;
                        case 'SILVER':
                            switch ($player['division']) {
                                case 'I':
                                    $sameCP['tier'] = 'y5';
                                    break;
                                case 'II':
                                    $sameCP['tier'] = 'y4';
                                    break;
                                case 'III':
                                    $sameCP['tier'] = 'y3';
                                    break;
                                case 'IV':
                                    $sameCP['tier'] = 'y2';
                                    break;
                                case 'V':
                                    $sameCP['tier'] = 'y1';
                                    break;
                                default:
                                    $sameCP['tier'] = 'Error Silver';
                                    break;
                            }
                            break;
                        case 'GOLD':
                            switch ($player['division']) {
                                case 'I':
                                    $sameCP['tier'] = 'x5';
                                    break;
                                case 'II':
                                    $sameCP['tier'] = 'x4';
                                    break;
                                case 'III':
                                    $sameCP['tier'] = 'x3';
                                    break;
                                case 'IV':
                                    $sameCP['tier'] = 'x2';
                                    break;
                                case 'V':
                                    $sameCP['tier'] = 'x1';
                                    break;
                                default:
                                    $sameCP['tier'] = 'Error Gold';
                                    break;
                            }
                            break;
                        case 'PLATINUM':
                            switch ($player['division']) {
                                case 'I':
                                    $sameCP['tier'] = 'w5';
                                    break;
                                case 'II':
                                    $sameCP['tier'] = 'w4';
                                    break;
                                case 'III':
                                    $sameCP['tier'] = 'w3';
                                    break;
                                case 'IV':
                                    $sameCP['tier'] = 'w2';
                                    break;
                                case 'V':
                                    $sameCP['tier'] = 'w1';
                                    break;
                                default:
                                    $sameCP['tier'] = 'Error Platinum';
                                    break;
                            }
                            break;
                        case 'DIAMOND':
                            switch ($player['division']) {
                                case 'I':
                                    $sameCP['tier'] = 'v5';
                                    break;
                                case 'II':
                                    $sameCP['tier'] = 'v4';
                                    break;
                                case 'III':
                                    $sameCP['tier'] = 'v3';
                                    break;
                                case 'IV':
                                    $sameCP['tier'] = 'v2';
                                    break;
                                case 'V':
                                    $sameCP['tier'] = 'v1';
                                    break;
                                default:
                                    $sameCP['tier'] = 'Error Diamond';
                                    break;
                            }
                            break;
                        case 'MASTER':
                            $sameCP['tier'] = 'u';
                            break;
                        case 'CHALLENGER':
                            $sameCP['tier'] = 'u';
                            break;
                        default:
                            $sameCP['tier'] = 'Error Tier';
                            break;
                    }
                    $sameCP['player'] = $player;
                    array_push($sameCPs, $sameCP);
                }
            }
            sort($sameCPs);
            foreach ($sameCPs as $sameCP) {
                array_push($playersByCP, $sameCP['player']);
            }
        }

        foreach ($playersByCP as $position => $playerByCP) {
            $tableRow = serialize($playerByCP);

            if ($playerByCP['gamesplayed'] >= 10) {
                $sql2 = 'INSERT INTO top_list (position, table_row, sum_name, champ_id) VALUES (' . $position . ', \'' . $tableRow . '\', \'' . mb_strtolower(str_replace(' ', '', $playerByCP['playerName']), 'UTF-8') . '\', \'' . mb_strtolower(str_replace(' ', '', $playerByCP['champId']), 'UTF-8') . '\')';

                if ($conn->query($sql2)) {
                    echo 'Insert: ' . mb_strtolower(str_replace(' ', '', $playerByCP['playerName']), 'UTF-8') . '<br>';
                } else {
                    echo 'Failed: ' . $conn->error . '<br>';
                }
            }
        }
    }
}
?>
Chris Forrence
  • 10,042
  • 11
  • 48
  • 64

1 Answers1

0

When editing the php.ini, make sure that it's the correct file you are editing. Take a look here: How to know which php.ini is used?

Try setting the execution time explicitly in the server configuration file:

max_execution_time = 360

The specific server configuration could be handling the defaults different from your local host.

Community
  • 1
  • 1
glaux
  • 701
  • 7
  • 20