GumSlone wrote:
Displaying ads on a site causes a high server load,
here is a code to check the server load and if its low then show an ad.
if(current_load()<50){
echo admob_request();
}
function current_load()
{
//GET SERVER LOADS
$loadresult = @exec('uptime');
preg_match("/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/",$loadresult,$avgs);
return $avgs[1];
}
Better is my variant 🙂.
# Gets system load average
# $time - integer
# 0 - system load average over the last minute
# 1 - system load average over the last 5 minutes
# 2 - system load average over the last 15 minutes
# 3 - system load average array over the last 1, 5 and 15 minutes
function server_load ( $time = 0 )
{
# Gets system load average array
$load = sys_getloadavg ();
return ( $time == 3 ? $load : $load [ $time ] );
}
# Usage
if ( server_load () < 50 )
{
echo admob_request();
}
I know that. When I diplayed the whole string, the loads were something like this.
0.0, 0.1, 0.0
How are these values gotten, and what they mean. That's what I wanted to understand.
frostymarvelous wrote:
I know that. When I diplayed the whole string, the loads were something like this.
0.0, 0.1, 0.0
How are these values gotten, and what they mean. That's what I wanted to understand.
Returns three samples representing the average system load (the number of processes in the system run queue) over the last 1, 5 and 15 minutes, respectively.
GumSlone wrote:
try optimizing it, install memcached to cache mysql queries, also install nginx for static content and you will reduce your server load up to 10.
Hmmm .. I installed memcache ... I got some error , I restart the apache and WOW , have never seen the CPU under 10 :-O
Thanks for the tip Gum 🙂
L.E. : ok ..maybe this low usage is because of apache restart .. I will wait to see how will work today ..
Now average is 5-6 😀