[英]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.