ElkArte Community

Project Support => Support => Topic started by: Mrs. Chaos on October 10, 2021, 12:34:19 pm

Title: Error in the Server.subs.php
Post by: Mrs. Chaos on October 10, 2021, 12:34:19 pm
Hello,
I keep getting the same three error messages. This is the case in my main forum and also in the test forum. I completely reinstalled the test forum yesterday, but one of the errors is already reported there.
It appears when I click on the admin button in the menu after logging in and also when I click on "Administration Center" in the menu on mouseover over the admin button.
That's the error message, what's wrong there in the code?

Type of error: General
Warning: Trying to access array offset on value of type bool
https://forum.xxx.de/index.php?action=admin;area=index;ac04180f1=c04180f1ed64deOM6BNBrU3bu8i6WRKm
File: /www/htdocs/xxx/xxx/sources/subs/Server.subs.php
Line: 34

Code: [Select]
30	// The internal function should always be available
31 if (function_exists('sys_getloadavg'))
32 {
33 $sys_load = sys_getloadavg();
34 return $sys_load[0] / $cores;
35 }

Regards
Mrs. Chaos
Title: Re: Error in the Server.subs.php
Post by: Arantor on October 10, 2021, 01:36:04 pm
sys_getloadavg() is for some reason returning false rather than an array - but I’m not on my desktop to look at the rest of it to see how safely to change it.

Maybe it should be
Code: [Select]
// The internal function should always be available
if (function_exists('sys_getloadavg'))
{
$sys_load = sys_getloadavg();

if (is_array($sys_load))
return $sys_load[0] / $cores;
}

Not 100% sure if the indentation is perfect, tabs on iPad are hard! But if it’s not an array it shouldn’t be using that method to return.
Title: Re: Error in the Server.subs.php
Post by: Mrs. Chaos on October 10, 2021, 02:32:06 pm
Thank you, that helped!
In both forums, the error messages now stay away. :)
Title: Re: Error in the Server.subs.php
Post by: Spuds on October 10, 2021, 06:27:38 pm
Interesting it is returning a bool.  I'll add this to the 1.1.9 tracker
Title: Re: Error in the Server.subs.php
Post by: Arantor on October 10, 2021, 09:16:41 pm
sys_getloadavg() does say in the manual it can return false. But it never explains why it would return false, merely 'on failure' and 'this isn't implemented on Windows' (not that the OP has a Windows setup)

SMF originally used a combination of querying /proc/loadavg and calling uptime on the command line to identify this.
Title: Re: Error in the Server.subs.php
Post by: Spuds on October 10, 2021, 11:36:47 pm
Well would you look at that, it indeed says array|false  :-[