简体   繁体   English

无限循环? 遗漏了什么? 我不知道发生了什么错误:500次超时(不应该发生)

[英]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. 我正在尝试创建一个PHP脚本,该脚本将撕碎一个Json文件并将其排序并发送到数据库,但是我不明白为什么会这样:我曾经遇到一个错误,说我超出了PHP的RAM限制(将其设置为无限制),但是现在出现超时错误。 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. 我有一种感觉,它是我的代码而不是服务器,但是在哪里,而while循环不是无限循环,我看不到任何错误。

<?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 true并输入循环体,然后

 $minTags++; 

will make sure that the condition is also true on the next iteration, because $tagsNum is not modified in the loop body. 将确保条件在下一次迭代时也true ,因为$tagsNum不会在循环主体中修改。 You have an infinite loops. 您有无限循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的 laravel.log 文件中有这个错误。 我不知道发生了什么 - i have this error in my laravel.log file. I don't know what is happening 我正在尝试制作一个登录页面。 然而,事情总是出错 - 我不知道是什么? - I am trying to make a login page. However something keeps going wrong - and I don't know what? 我的代码出了点问题,我也不知道, - Something is wrong with my code and i don't know what, 我正在尝试将分页功能集成到kohana中,但不知道发生了什么。 我收到这些错误“未定义的变量:传呼机” - I am trying to integrate pagination in kohana, but don't know what is happening. I get these error “ Undefined variable: pager” mysqli不应该发生的php错误 - Php error that shouldn't be happening with mysqli 我的 session 代码有问题,我不知道发生了什么? - I have some problem in my code with session and I don't know what is going on? PHP准备好的语句无法正常工作,我也不知道出了什么问题 - PHP prepared statement cannot work.And I don't know what is going wrong 使用搜索词PHP从MySQL提取。 我不知道怎么了 - Drawing from MySQL using a search term PHP. I don't know what is going wrong Symfony 错误 - 我不知道这是什么意思 - Symfony error - I don't know what it means 我不知道该怎么称呼php / css error tho - I don't know what to call it php/css error tho
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM