Reputation: 117
I keep seeing a memory exhausted error
PHP Fatal error: Allowed memory size of 268 435 456 bytes exhausted
in my log file.
This error comes randomly even when the server is very lightly loaded & not reproducible on localhost. I have a VPS 4 server from hostgator with with loads of MB. The php config allows upto 256 Mb.
The code is below
function func_select_array($qry)
{
$i=0;
$data=array();
$qry_result=mysql_query($qry);
if($qry_result)
{
while ($row=mysql_fetch_assoc($qry_result))
{
$data[$i] = $row;
$i++;
}
return $data;
}
else
{
return 2;
}
}
function func_check_rule_out_bid($auc_id,$bid_amount,$return_freq,$recheck)
{
$bid_qry="select * from tbl_bid where ubaid='".$auc_id."' and ubf='1' order by uba desc limit 0,10";
$bid_array=func_select_array($bid_qry);
}
The table tbl_bid has 2800 records. I get memory exhausted error in the while loop inside func_select_array function. I cannot imagine this query needs 256M+. It does not appear to be a php problem, but something in mysql. Please help...
Upvotes: 1
Views: 4366
Reputation: 392
You should use EXPLAIN to youre query. To assure that youre not doing some heavy query(at first look doesnt seem).
At second way, may be are you getting some BLOB ot TEXT field that is too heavy. Not at your local, thats why your not able to get this at local enviroment.
Assure that youre not getting an infinte loop. Could be?
Use trace php errors and try/catch this block to get better information about the error.
try {
while ($row=mysql_fetch_assoc($qry_result))
{
$data[$i] = $row;
$i++;
}
} catch (Exception $e) {
debug_print_backtrace();
var_dump($e->getMessage());
}
Upvotes: 0
Reputation: 111249
Memory exhaustion can be very difficult to debug because the error only tells you where the memory finally ran out, not where the bulk of it was used.
You could use a memory profiler, such as the one in Xdebug, to find where all that memory went.
Upvotes: 1