PHP Fatal error

Hello, I noticed I am having an issue with my site, I keep getting a blank white page on one section on our downloads section, after looking around I saw this in the error log.

[30-Aug-2012 20:02:55 UTC] PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 89019 bytes) in /home/public_html/modules/Downloads/includes/functions.php on line 198

When i went to line 198, this is what I find:
[php] $result = $db->sql_query(“SELECT * FROM “.$prefix.”_downloads_categories WHERE cid=’$parentid’”);[/php]

which that line is pulled from this section:
[php]function getparent($parentid,$title) {
global $prefix,$db;
$result = $db->sql_query(“SELECT * FROM “.$prefix.”_downloads_categories WHERE cid=’$parentid’”);
$cidinfo = $db->sql_fetchrow($result);
if ($cidinfo[‘title’] != “”) $title = $cidinfo[‘title’]." -> ".$title;
if ($cidinfo[‘parentid’] != 0) { $title=getparent($cidinfo[‘parentid’], $title); }
return $title;
}[/php]

I just don’t see what could be causing it especially when I know this module is working on many other sites out there. Could it be something with the host?

I have tried creating a php.ini file and changing the memory limit as I found from a search and that did not work.

134217728 bytes is 128MB depending on what your queries are returning it seems you have a memory leak somewhere on your host and you host cannot allocate memory on the fly to cover for the overages. I would crank your php.ini memory limit to something like 512 and see how you do if you even have access to edit that file on your host… you can not just go create one… you should edit the “official” one I generally find them in /etc/apache2/php5/…

This is a recursive function — it calls itself.

[php] if ($cidinfo[‘parentid’] != 0) { $title=getparent($cidinfo[‘parentid’], $title); }
return $title;
[/php]

It keeps retrieving data until it gets a record where the [tt]parentid[/tt] is not equal to zero.

First: Check your database, it appears that you have a circular definition. That is the record with cid=’#1’ has parentid = ‘#2’ and the record with cid=’#2’ has parentid = ‘#1’. The loop may not be that small, there may be several 1 -> 2 -> 3 -> 4 -> 1 -> 2 -> 3 -> 4 -> 1 …

Also: Change [tt]if ($cidinfo[‘parentid’] != 0)[/tt] to [tt]if (empty($cidinfo[‘parentid’]))[/tt]. That probably will not make any difference and is most likely completely unnecessary, but, it looks cleaner, anyway.

Also: If you expect these to be long chains, you should review the database class you are using and add a call to release the query resource after you get the row data. As it is, you are creating one resource after another and they are holding memory (a memory leak).

Also: Do not use [tt]SELECT *[/tt], select only the columns you need. All columns you select (and SELECT * selects ALL columns in the row) are returned to the PHP script and are help in memory.

Unless these are really long chains, you should not need to expand the memory limit.

Sponsor our Newsletter | Privacy Policy | Terms of Service