Division by zero in functions.php
#1
Hi all!

After moving MyBB from a Windows/IIS server to Linux/Apache, I now and then get a division by zero error on loading the forum web pages (not always).

The error message is:

Warning: Division by zero in /var/www/mybb/inc/functions.php on line 28
Warning: Division by zero in /var/www/mybb/inc/functions.php on line 29
Warning: Cannot modify header information - headers already sent by (output started at /var/www/mybb/inc/functions.php:28) in /var/www/mybb/inc/functions.php on line 78


The code at lines 28/29 reads:

$percentphp = number_format((($phptime/$maintimer->totaltime)*100), 2);
$percentsql = number_format((($querytime/$maintimer->totaltime)*100), 2);

So, apparantly $maintimes->totaltime at some occasions is zero. Anyone know what may cause this problem?
#2
MyBB version ?
#3
LeX- Wrote:MyBB version ?

MyBB: 1.2.9
Ubuntu: 7.10
PHP: 5.2.3-1ubuntu6
MySQL: 5.0.45
#4
Hmm, you must have a fast server Toungue

Replacing your above code sample with the following should fix it:
if($maintimer->totaltime)
{
$percentphp = number_format((($phptime/$maintimer->totaltime)*100), 2);
$percentsql = number_format((($querytime/$maintimer->totaltime)*100), 2);
}
else
{
$percentphp=0;
$percentsql=0;
}

Probably good idea to file a bug report too Toungue
#5
This is a bug with your server (I've seen it before) - The kernel in some cases is buggy under certain circumstance and the time stamp reverses itself anywhere from a millisecond to 2 seconds causing it to generate that.
#6
Thanks for you replies. I already implemented a almost identical fix as you suggested Zinga (only thing is that i do $percentphp="?" instead of $percentphp=0), and am satistfied with that. It's not that it's a critical function of the forum. Smile

The server runs in a 32-bit VM under VMware server. The host is a 64-bit Ubuntu 7.10 server on a AMD dual core CPU. I understand that this can cause "certain circumstanses".

But the work-around works fine, so you can consider the case closed. Thanks for your help!


Forum Jump:


Users browsing this thread: 1 Guest(s)