-2

As the title suggests, I am receiving an error when loading my website, Minecraft-Seeds.net It runs using the AV Arcade script, and has been running fine without any hitches for the past year and a half. Recently, the website has been giving me the memory error, and we have made absolutely no changes to the code and even restored previous backups of the website. Our visits have not gone up crazily to explain an increase in resource usage, as we have had a low month this month with around 300,000 visits.

The popular suggestion here Allowed memory size of 33554432 bytes exhausted (tried to allocate 43148176 bytes) in php does not work, as my script has an actual issue which is causing it to use much more memory than I have.

I have looked through the code and am not sure as to where exactly I should begin looking. The mySQL queries appear to have LIMITs on them, so I'm not sure what is causing the error.

If you go to the website right now, it will give you the following place as the origin of the error:

/home/mineseed/public_html/config.php on line 39

This line of code is as follows$new_plays = 4; And I have tried commenting it out, and it results in the error simply jumping around my site to line after line of code, with no clear solution in sight.

Any help is greatly appreciated.

EDIT I've added the config.php file

<?php
// mySQL information
$server = 'localhost';                   // MySql server
$username = 'user';                      // MySql Username
$password = 'pass';                         // MySql Password
$database = 'database';                  // MySql Database

// The following should not be edited
  $con = mysql_connect("$server","$username","$password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("$database", $con); 

//mysql_query("UPDATE ava_games SET height='300' WHERE height='0'") or die (mysql_error());

//
$sql = mysql_query("SELECT * FROM ava_settings");
$row = mysql_fetch_array($sql);
$site_name = $row['site_name'];
$site_description = $row['site_description'];
$site_keywords = $row['site_keywords'];
$site_url = $row['site_url'];
$seo_on = $row['seo_on'];
$template_url = $row['template_url'];
$max_results = $row['max_results'];
$image_height = $row['image_height'];
$image_width = $row['image_width'];
$adsense = $row['adsense'];
$cat_numbers = $row['cat_numbers'];
$email_on = $row['email_on'];
$add_to_site = $row['add_to_site'];
$plays = $row['plays'];
$language = $row['language'];
$featured = $row['featured_games'];
$play_limit = $row['play_limit'];
$adsense_id = $row['adsense_id'];
$new_plays = 4;

// Convert super globals 
if (phpversion() >= '5.0.0') 
{ 
    $HTTP_POST_VARS = ($_POST); 
    $HTTP_GET_VARS = ($_GET); 
}
?>
4

3 回答 3

1
  1. 首先,您需要检查您是否在 php 脚本中使用递归,因为有时递归失败,这就是发生此错误的原因。

  2. 如果您使用的数组过多,请在使用后取消设置,以便释放一些内存用于其他执行。IE:unset($array)

  3. 请增加您的内存限制php.ini或使用 php 函数ini_set('memory_limit','128M');或使用.htaccess文件覆盖memory_limit

于 2012-12-01T18:32:29.600 回答
0

尝试在第 39 行之前取消设置不需要的变量并腾出内存。另外,继续清理后面的代码。虽然不是首选,但您也可以在 php.ini 中增加内存分配。

查询可以通过只拉入那些需要的列来提高效率,

   Select column1, column2......

确保列具有索引以获得更快的结果。如果您确定需要检索的结果数量,查询还需要使用“限制”。

于 2012-12-01T18:25:05.973 回答
0

我很抱歉我的英语。如果不查看代码,很难判断内存泄漏在哪里。是的,我同意所有修复(增加 php 内存,并限制查询中的行)。当您使用数组或大文件(解析 xml)或类似的东西时,内存可能会落在某个地方。尝试查找增加内存的代码部分,使用 var_dump()、debug_backtrace(),或尝试使用记录所有变量的库

于 2012-12-01T18:33:37.343 回答