简体   繁体   中英

Infinate loop? Missing something? I don't know what going on Error: 500 time out (Shouldn't be happening)

I am trying to create a PHP script that will rip apart a Json file sort it and send it up to the database, however I don't understand why this is happening: I used to get a error saying I exceeded the RAM limit for PHP (Set it to unlimited) but now I get a time out error. I have a feeling that its my code and not the server but I don't see anything wrong where and the while loop is not an infinite loop.

<?php

    //Set Ram Limit to Unlimited
    ini_set('memory_limit', '-1');

    //Improper Variables.
    $tags = '';
    $minTags = 1;
    $value = '';

    //Initialize Database Variables.
    $host = 'localhost';
    $username = 'icangame_dataa';
    $password = '**********************************';
    $dbname = 'icangame_data';

    //Get Game Content
    $linkFolder = $_POST['linkToFile'];
    $file = '../games/'.$linkFolder.'/__metadata__.json';
    $json = json_decode(file_get_contents($file), true);

    //Take Apart the JSon
    $width = $json['width'];
    $height = $json['height'];
    $author = $json['author'];
    $thumbnail_url = $json['thumbnail_url'];
    $description = $json['description'];
    $controls = $json['controls'];
    $developer = $json['developer'];
    $name = $json['name'];
    $developer_url = $json['developer_url'];
    $tagsArray = $json['tags'];

    //Process My Tags
    $tagsNum = count($tagArray);

    while ($minTags > $tagsNum) 
    {

        $tagsTricky = "'.tags.'";
        $minTagsTricky = "'".$minTags."'";
        $value = $json[$tagsTricky[$minTags]];
        $tags.=$value.' ';
        $minTags++;

    }

    //Database Connection
    $myCon = mysqli_connect($host, $username, $password, $dbname);

    if (mysqli_connect_errno($myCon))
    {

        echo "Error Connection:".mysqli_connect_error();

    }

    //Checking if Item already exists.
    $gameItem = mysqli_query($con,"SELECT $name FROM gameList");

    if (!$gameItem == $name)
    {

        //Sending Data to Database.
        mysqli_query($myCon, "INSERT INTO gameList (width, height, author, thumbnail_url, description, controls, developer, name, developer_url, tags) 
            VALUES ('$width', '$height', '$author', '$thumbnail_url', '$description', '$controls', '$developer', '$name', '$developer_url', '$tags')");

    } 
    else
    {

        echo "Item ".$name." already exists! Sorry, someone beat you to it. ;c";

    }



?>

If the condition in

 while ($minTags > $tagsNum) 

is true and the loop body is entered, then

 $minTags++; 

will make sure that the condition is also true on the next iteration, because $tagsNum is not modified in the loop body. You have an infinite loops.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM