check server load and if a server is buisy block download/ad request.

Started on the old forum in December 2010 · view the original in the archive · old links redirect here

10 replies · 1,530 views · started 15 years ago · 1 min read

TL;DR · summary of 10 replies
  • - The values in the array represent the average system load over the last 1, 5 and 15 minutes, respectively.
  • - Uptime is not directly related to server load; it refers to how long a computer or network has been operational.

Written automatically from the replies by a language model on our own server. It can be wrong; the posts below are the source.

5 participants
GumSlone Administrator Principal · 1,690 posts #1

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];
}

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

frostymarvelous Senior · 266 posts #2

Thanks for the code. Could you explain the values in the array please? What each one means? Thanks.

Perfection comes at a cost

I accept liberty!

MuniGod Junior · 23 posts #4

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(); 
}

www.wapruby.com - Create your own WAP site and earn money.

frostymarvelous Senior · 266 posts #5

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.

Perfection comes at a cost

I accept liberty!

morency Senior · 488 posts #6

mine is up to 35-42 with just 300 users online :-/

Unamos los corazones,hoy todos somos multicolores!

MuniGod Junior · 23 posts #7

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.

www.wapruby.com - Create your own WAP site and earn money.

GumSlone Administrator Principal · 1,690 posts #8

morency wrote: mine is up to 35-42 with just 300 users online :-/

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.

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

frostymarvelous Senior · 266 posts #9

Thank you so much.

Perfection comes at a cost

I accept liberty!

morency Senior · 488 posts #10

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 😀

Unamos los corazones,hoy todos somos multicolores!

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close