Hi guys,
I am still trying to isolate why this particular get method requires so many resources to run.
Overtime, as the number of rows in the table has increased, I have had to increase the amount of memory for PHP to run the page. Of course, if PHP runs out of memory before executing the script, it will produce a blank white page.
For ages I thought it was an Apache / PHP config issue, but I noticed as the number of rows increased, so did the amount of memory required to return a single row.
I can understand how if you are selecting all rows for example, and then returning XoopsObjects for each of the rows, it would become a problem as the size of the table increases. However, as far as I understand it, the get method only returns a single row and then constructs a XoopsObject for that particular row, so the number of rows in the table should not have such a significant impact on the memory required to build a single XoopsObject.
This is the error produced by PHP in the PHP Log:
[21-Jan-2010 16:24:28] PHP Fatal error: Allowed memory size of 104857600 bytes exhausted (tried to allocate 140 bytes) in /Applications/MAMP/htdocs/site/kernel/object.php on line 186
So the page fails to load even though I have allocated PHP 100MB of memory to execute scripts. I have now allocated 500MB but of course this is only a temporary fix to the problem. As you can see I am running the MAMP stack on my Apple. However, experience the same issues on my Linux deployment as well.
The code breaks in object.php at this point:
/** * assign values to multiple variables in a batch * * @access private
* @param array $var_array associative array of values to assign */
function assignVars($var_arr) {
foreach ($var_arr as $key => $value) {
$this->assignVar($key, $value);
}
}
Of course I could just do a straight select and return an array:
Select * from smartobject_items where itemid = 1
which only needs 0.001 seconds to execute instead of 5 seconds when executing:
$itemObj = $smartsection_item_handler->get($itemid);
However, this would become messy over time and does not conform to XOOPS programming standards.
So, any suggestions on how I could optimize the get method so that the amount of memory required to perform the operation does not need to increase according to the number of rows in the table, for selecting on 1 row from the table.
Much appreciated.