using PHP Version 5.3.5
I am going insane.
This piece of code is giving me hard time. After I refresh the page on Apache a few times, I get weird results. I think I have a memory leak here, but I can’t find out why.
Please help !
<?php
function ost($active_sub_time,$arr_subscription_values)
{
$result=0;
while($active_sub_time>=12)
{
$active_sub_time-=12;
$result+=($arr_subscription_values['COST_12']);
}
while($active_sub_time>=6)
{
$active_sub_time-=6;
$result+=($arr_subscription_values['COST_6']);
}
while($active_sub_time>=3)
{
$active_sub_time-=3;
$result+=($arr_subscription_values['COST_3']);
}
while($active_sub_time>=1)
{
$active_sub_time-=1;
$result+=($arr_subscription_values['COST_1']);
}
if($active_sub_time>0)
$result+=($active_sub_time)*($arr_subscription_values['COST_1']);
if (!is_numeric($result))
{
echo"<br> Bug occurred";break; // print other values if necessary
}
return $result;
}
$datetime1 = date_create('2009-01-11');
$datetime2 = date_create('2001-11-09');
$interval = date_diff($datetime1, $datetime2);
$num_of_months = ($interval->y)*12 + ($interval->m) + ($interval->d)/(cal_days_in_month(CAL_GREGORIAN, $datetime2->format("m"), $datetime2->format("Y")));
$v = array('COST_1'=>'3.99','COST_3'=>'9.99','COST_6'=>'15.99','COST_12'=>'24.99');
echo "OPT value for $num_of_months months=".ost($num_of_months,$v);
?>
I do get this result at first:
OPT value for 86.066666666667 months=183.176
But after a few refreshes I get this :
OPT value for G.GMMMMMMMMMMMN months=183.176
Does anyone know why this is ?
Thanks
Cannot reproduce, I used your code exactly, and executed it multiple times. It displays the same result.
There may be an issue with your server, or mashing refresh over and over is causing some kind of problem or memory limit.
Check your php.ini and see if your memory limit is set too low, or max requests?