work_it_work Posted February 6, 2013 Share Posted February 6, 2013 (edited) 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 February 6, 2013 by work_it_work Quote Link to comment https://forums.phpfreaks.com/topic/274112-get_setverload-function-stopped-wirking-please-help/ Share on other sites More sharing options...
Christian F. Posted February 6, 2013 Share Posted February 6, 2013 (edited) 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 February 6, 2013 by Christian F. Quote Link to comment https://forums.phpfreaks.com/topic/274112-get_setverload-function-stopped-wirking-please-help/#findComment-1410467 Share on other sites More sharing options...
work_it_work Posted February 6, 2013 Author Share Posted February 6, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/274112-get_setverload-function-stopped-wirking-please-help/#findComment-1410473 Share on other sites More sharing options...
Christian F. Posted February 6, 2013 Share Posted February 6, 2013 Yes, the error log is empty because you were suppressing the errors. Try running the script after removing all of the @ in there, and you should be getting something. Quote Link to comment https://forums.phpfreaks.com/topic/274112-get_setverload-function-stopped-wirking-please-help/#findComment-1410477 Share on other sites More sharing options...
work_it_work Posted February 6, 2013 Author Share Posted February 6, 2013 (edited) well, i have removed the all the @ in there and nothing happens... checked the error log of the hosting provider and no errors... what else should i do? Edited February 6, 2013 by work_it_work Quote Link to comment https://forums.phpfreaks.com/topic/274112-get_setverload-function-stopped-wirking-please-help/#findComment-1410492 Share on other sites More sharing options...
Christian F. Posted February 6, 2013 Share Posted February 6, 2013 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? Quote Link to comment https://forums.phpfreaks.com/topic/274112-get_setverload-function-stopped-wirking-please-help/#findComment-1410494 Share on other sites More sharing options...
work_it_work Posted February 6, 2013 Author Share Posted February 6, 2013 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) Quote Link to comment https://forums.phpfreaks.com/topic/274112-get_setverload-function-stopped-wirking-please-help/#findComment-1410499 Share on other sites More sharing options...
Christian F. Posted February 6, 2013 Share Posted February 6, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/274112-get_setverload-function-stopped-wirking-please-help/#findComment-1410501 Share on other sites More sharing options...
work_it_work Posted February 6, 2013 Author Share Posted February 6, 2013 please be kind enough and help me to echo everything Quote Link to comment https://forums.phpfreaks.com/topic/274112-get_setverload-function-stopped-wirking-please-help/#findComment-1410505 Share on other sites More sharing options...
Christian F. Posted February 6, 2013 Share Posted February 6, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/274112-get_setverload-function-stopped-wirking-please-help/#findComment-1410535 Share on other sites More sharing options...
work_it_work Posted February 6, 2013 Author Share Posted February 6, 2013 (edited) 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 February 6, 2013 by work_it_work Quote Link to comment https://forums.phpfreaks.com/topic/274112-get_setverload-function-stopped-wirking-please-help/#findComment-1410577 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.