Jump to content

Recommended Posts

I AM SORRY THE CORRECT TOPIC IS GET_SERVER_LOAD FUNCTION STOPPED WORKING - MODERATOR PLEASE EDIT IF POSSIBLE

 

this function was working for 3 months and yesterday stopped working... please help me to understand why

 

here's the function:

define ('GMSG_NA', 'actual load is:');
function get_server_load()
{
$output = GMSG_NA;
$os = strtolower(PHP_OS);


if(strpos($os, "win") === false)
{
if(@file_exists("/proc/loadavg")) {
$load = @file_get_contents("/proc/loadavg");
$load = @explode(' ', $load);


$output = $load[0];
}
else if(@function_exists("shell_exec"))
{
$load = @explode(' ', `uptime`);
$output = $load[count($load)-1];
}
}


return ($output > 0) ? $output : GMSG_NA;
}

 

and here's the output

 

$site_status['server_load'] = get_server_load();

 

please help me understand why stopped working suddenly

Edited by work_it_work

First order of business is to remove all of the error suppression, then you should either enable the error reporting (on your dev server) or check the error logs (on your production server).

If you still can't figure out what's going on, please post the error messages here so that we can help. A proper description of what "it stopped working" means would be appreciated as well, so that we know what it is supposed to do and what it is doing.

 

By hiding the errors the way you've done above, you will not be told when something goes wrong, nor why. Thus making it impossible to properly debug the script. That's the primary reason why we strongly recommend against such practices.

Edited by Christian F.

thanks for your reply. please excuse my typing errors, i'm tired because i am trying to fix this from yesterday without sleeping.

this script is not is a part from a larger project which was bought 3 months ago...

in the server error log can't find anything. it's empty, i just looked. also the cpu usage is low and there are no processes... this mean the script it's not working at all...

please help me to debug and show errors maybe the script will work again.

You still haven't explained how it "stopped working", or what that actually entails. From what I can see, and you've told me, there are no direct errors in the code. Which indicates that it's a problem with the logic of the surrounding code.

 

Also, what changed on your server yesterday?

The function worked just fine until yesterday. it showed the actual avg server load. now it's displaying N/A. I have no idea why it's not working anymore. Is it possible the hosting company to ban this function or something?

The function is the same as 2 months ago when it worked.

 

I do not receive any error message, just instead of Server Load : 3.87 (example) it shows now N/A (not available)

I see. Well, that means that the PHP code is working, or at it's doing what it has been doing. I assume something else has changed on your server, which either caused the result returned from /proc/loadavg or uptime to change. You should ask your host about that.

 

Also, echoing out the full returned value from the command used might be useful. At the very least you'll be able to see what you're getting, and give you the opportunity to adjust the offsets if they're wrong.

If you're looking for someone to fix this for you, you'll want to ask this in the Freelance section.

This section is for getting help to make your code work, with us providing you tips on what you should do yourself when you've hit a wall. Getting help means you have to do most of the work yourself, and requires you to understand (or at least learn) what you're doing. Us writing the code to echo out variables for you is neither.

 

thanks for your reply.... i tried something and i think the issue is caused by the hosting provider:

 

 

if (file_exists("/proc/loadavg")) {
echo "The file /proc/loadavg exists";
} else {
echo "The file /proc/loadavg does not exist";
}

 

the result is "The file /proc/loadavg does not exist" ....

 

now i found another way to call the server load

 

if(function_exists("sys_getloadavg"))
{
// sys_getloadavg() will return an array with [0] being load within the last minute.
$serverload = sys_getloadavg();
$serverload[0] = round($serverload[0], 4);
}

 

this one seems to work....

 

 

let me know if i am wrong in the first case where the file is missing....

Edited by work_it_work
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.