나는이 문제에 대해 정신적으로 다가갔습니다. 나는 이것을 한 번도 해본 적이 없다고 확신하지만, 뭔가 바꾸어 놓았을 것입니다. 배열에 추가 할 때 PHP 스크립트는 항상 메모리 제한을 초과합니까?
이
문제의php
스크립트입니다 : 나는 그것을 실행할 때마다
<?php
echo <<<START
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Spotify Community Staff Tracker</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
<meta http-equiv="Content-Type" content="text/xhtml; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script type='text/javascript' src='scripts/respond.min.js'></script>
</head>
<body>
START;
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
require_once('config.php');
$posts = array();
$db = new mysqli($config['host'], $config['user'], $config['password'], $config['database']);
if (($result = $db->query('SELECT * FROM `posts`')) != false)
{
while (($obj = mysqli_fetch_object($result)) !== false)
{
if (@$_GET['idfilter'] && @$_GET['idfilter'] != $obj->board)
{
continue;
}
$posts[] = array('datetime' => $obj->datetime, 'subject' => $obj->subject, 'post_url' => $obj->post_link, 'user_url' => $obj->author_link, 'user' => $obj->author_name);
}
if (sizeof($posts) == 0)
{
if ($_GET['idfilter'])
die("Filter caused zero result, or cron hasn't run.");
die("Cron hasn't been run.");
}
}
else
{
die("An error occured.");
}
$lupdate = mysqli_fetch_object($db->query("SELECT * FROM `last_update`"));
echo <<<BOTTOM
<div id="right" class="fixed">
<p id="lastupdate">Last Updated: {$lupdate->timestamp}</p>
<p><form id="filter" action="" method="get">
<input type="text" placeholder="Enter a forum id to filter..." name="idfilter" />
<input type="submit" value="Filter" id="submit" />
</form>
</p>
</div>
BOTTOM;
echo("\n<div id=\"posts\">");
foreach (array_reverse($posts) as $post)
{
echo("\n<p><a class=\"postlink\" target=\"_blank\" href=\"{$post['post_url']}\">{$post['subject']}</a> - by <a class=\"suser\" target=\"_blank\" href=\"{$post['user_url']}\"><img src=\"http://spotify.i.lithium.com/html/rank_icons/spotify_icon_new.png\" alt=\"Spotify Staff\" />{$post['user']}</a> <span class=\"datetime\">on {$post['datetime']}</span>\n</p>");
}
echo("\n</div>");
echo <<<END
\n</body>
</html>
END;
?>
나는 다음과 같은 오류 얻을 :
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 44 bytes) in <filepath>\index.php on line 36
그건 항상 동일한 오류 - 동일 할당, 같은 라인을 . 움직이는 것을 시도해 보았습니다. 객체가 아닌 배열을 사용하려고했습니다.
에 대한 아이디어는 왜 많은 양의 메모리를 사용하려고합니까? 그것은이 라인의
ini_set('memory_limit','256M');
난 당신이 작은 자기 문제를 가지고 예를 포함 할 좋습니다. 우리가 내부에서 필요로하지 않는 모든 HTML 등으로, 코드가 무엇인지 알아내는 것은 너무 많은 일이며, 이것은 당신이 쉽게 할 수있는 일입니다. http://sscce.org/을 참조하십시오. – Nanne
@ Nanne 코드 섹션이 독자적으로 이해되지 않을까 걱정되었습니다. 다음 시간 동안 주목 받았다. –