krakjoe November 15th, 2007, 07:27 http://interviolet.com/download/php_loadavg/php_loadavg.zip
An extension to check loadaverage on execution and halt execution / redirect browser if above a certain level for the last one five or ten minutes ...
Download to your computer somewhere and open load.c
PHP_INI_BEGIN()
PHP_INI_ENTRY("loadavg.one", "0.3", PHP_INI_ALL, NULL )
PHP_INI_ENTRY("loadavg.five", "0.5", PHP_INI_ALL, NULL )
PHP_INI_ENTRY("loadavg.ten", "0.5", PHP_INI_ALL, NULL )
PHP_INI_ENTRY("loadavg.redirect", "http://google.com", PHP_INI_ALL, NULL )
PHP_INI_END()
PHP_INI_ENTRY( string name, string value, PHP_INI_ALL, NULL )
edit the above entries to something that your server can cope with ( higher than 1.0, and keep the decimal point ), also change loadavg.redirect to some page on your server like
"PHP is smashing all the resources, blame Johnson"
then upload the files to a newly created directory anywhere on your server, and do the following ...
cd /path/to/newly/created/directory
phpize
./configure --enable-loadavg
make
make install
add loadavg.so to your extension loaders in php.ini
Problem avoided, of course you could create a php.ini just for one user, so long as you're root the user can't change it and ini_set( ) from php will be ignored, the only values used are the ones in load.c .....
Decker November 15th, 2007, 08:52 Won't configure :crying5:
in var/opt so that bits okay?!
krakjoe November 15th, 2007, 08:53 show me error ... I built a copy for your version of php in /home/intervio @ loadavg.so
Decker November 15th, 2007, 08:56 ./configure --enable-loadavg
-bash: ./configure: No such file or directory
krakjoe November 15th, 2007, 08:59 copy and paste this code in your terminal
cd /var/opt/phpize && phpize && ./configure --enable-loadavg && make && make install
phpize is a command, it generates a configure script from config.m4 files, there is no configure right now ....
Decker November 15th, 2007, 09:05 That did it :)
Changed to values in load.c ;
PHP_INI_BEGIN()
PHP_INI_ENTRY("loadavg.one", "1.0", PHP_INI_ALL, NULL )
PHP_INI_ENTRY("loadavg.five", "1.5", PHP_INI_ALL, NULL )
PHP_INI_ENTRY("loadavg.ten", "2.5", PHP_INI_ALL, NULL )
PHP_INI_ENTRY("loadavg.redirect", "http://www.web-spot.co.uk/alert.jpg", PHP_INI_ALL, NULL )
PHP_INI_END()
krakjoe November 15th, 2007, 09:07 yeah you still have to add it to /usr/local/lib/php.ini, where all the other extension=whatever.so lines are, just add
extension=loadavg.so at the end ... then httpd restart
Decker November 15th, 2007, 09:35 Already done - I might change the landing page though :D maybe.
krakjoe November 15th, 2007, 09:57 its not loaded .... don't see it added in php.ini ....
Decker November 15th, 2007, 10:00 Haven't restarted httpd yet ;)
Don't tell me you were going to test it out ??
krakjoe November 15th, 2007, 10:03 I tested already, just noticing that it's not loaded dispite being installed ... so thought I would say I can't see it in php.ini ( I can't write that file but can read it ) ....
Decker November 15th, 2007, 10:15 Try it now :)
krakjoe November 15th, 2007, 10:19 now it's loaded :) I feel much better ....
Decker November 15th, 2007, 10:24 So do I for some strange reason - cough.....
Nice work Joe :D
JonnyH November 15th, 2007, 11:23 That could really come into play for people like us, running free hosts. Cheers Joe once again.
Decker November 15th, 2007, 11:26 Just don't ask what inspired it :lol:
krakjoe November 15th, 2007, 11:39 That could really come into play for people like us, running free hosts. Cheers Joe once again.
That's what I hope ... not just free hosts, all servers have no good reason to exceed their resource limits, often when servers are under too much pressure more goes wrong than meets the eye ( disk read/write errors eventually break equipment ). Everyone knows, a computer, any computer, has a limit and you should enforce it, if your load average is too high then you should simply stop serving requests untill it goes down, it's only fair to all your users to do so ... and now you can ....
serverorigin November 16th, 2007, 00:55 Agreed. Nice contribution!
Dropped in on 8 servers -- guess we can see real fast how well it works :P
krakjoe November 16th, 2007, 02:35 I have also installed it on spacesocket.com it's working well there :)
Something I forgot to mention, don't change redirect for a php page, because you will cause an infinite loop of redirection, make it an image like decker or a static html page like http://spacesocket.com/loadavg.html
JonnyH November 17th, 2007, 02:48 After i've installed ASP.NET on this CentOS Server I'll get busy with this.
krakjoe November 17th, 2007, 03:08 That doesn't work so well johnny, decker has that installed and I messed with it a little, it's not really usable for full on applications and in my opinion is a huge waste of resources in itself. Mono is a great project, but the facts are that asp.net/C# is closed source so they'll never be able to emulate it properly .... probably in a few years time they will have studied it so much that it will be usable, but right now, not so much .... if you wanna learn/offer asp.net hosting, then get a windows box ( it shames me to say ) ....
JonnyH November 17th, 2007, 03:11 OK, well I installed mono, but to get the ASP installed it was some other things stringed onto it. They reported dependencies which reported the dependencies of which I'm trying to install if your with me :P
I'll get onto your project now.
JonnyH November 17th, 2007, 03:27 I've installed it now, i've added it in the php.ini but I don't know if it's loaded.
Check PHP Version here:
http://kwix-host.com/status/index.php?action=phpinfo
krakjoe November 17th, 2007, 03:33 <?php
echo "<pre>";
print_r( get_loaded_extensions( ) );
echo "</pre>";
?>
PS. When you add new extensions to php.ini you have to httpd restart
JonnyH November 17th, 2007, 04:08 I did, just forgot to mention it in my post ;)
http://kwix-host.com/cpaddon/extensions.php
It doesn't look to be there, I posted exactly what you said to add to your php ini. Would it be a different path though.
krakjoe November 17th, 2007, 04:25 show me the output from the make and make install command .... and also, try ...
<?php
dl("loadavg.so");
echo "<pre>";
print_r( get_loaded_extensions( ) );
echo "</pre>";
?>
JonnyH November 17th, 2007, 05:43 http://kwix-host.com/cpaddon/extensions.php
Got an error.
I haven't got the make and make install logs, but they did install fine without no errors.
krakjoe November 17th, 2007, 06:13 pm me with an ftp login for that server so I can have a look please ... the only thing I can think of is that you have put a ; infront of the extension line by accident ...
Decker November 17th, 2007, 10:24 With Joe on this one Jonny, he has a 'privilaged spot' on a server and adding mono sent resouce usage up by about 1% on one CPU with no activity on it, not a problem as it's a well heavy resourced server to start with.
It is a great project but a PITA, and I'm confused as to why you should have to make any changes other than the standard install?
Honestly get a window box (get it Windows Box :D ) asp/net is MS orientated so far, I'm bloody impressed at Joe getting anything to work under it on a *nix box to be honest :)
krakjoe November 17th, 2007, 10:34 Still no luck with loadavg johnny ?? 10 people installed it in the last 24 hours so I know it's not the code ... it even compiles for php6 ( that's what I tested it with ) ...
Decker November 17th, 2007, 10:52 I stuck it in the php.ini location and no worries, you could try that rather than paths.
krakjoe November 17th, 2007, 11:42 you should never include a path in an extension= directive, php automatically knows the location to load libraries from using the Zend API number and the --prefix= from ./configure when php is built ...
Jackel.ca November 17th, 2007, 11:45 Very clever.
Excellent work Joe!
Decker November 17th, 2007, 11:49 you should never include a path in an extension= directive, php automatically knows the location to load libraries from using the Zend API number and the --prefix= from ./configure when php is built ...
Long way of saying if the locate db is up to date it can find it :lol:
Your are getting too pro Joe, it's wearing off an the skills are escaping...
krakjoe November 17th, 2007, 12:57 actually, no ... it's got nothing to do with the file database, php knows becuase library paths are hardcoded, every version of php has a different zend api number, together with the hardcoded library paths made by configure it can work out which directory to load modules from ... this allows you to have more than one version of php, plus you're not required to name extensions with the php_ convention, so it keeps php from confusing it's modules from say lighttpd, or apache modules ...
JonnyH November 17th, 2007, 14:40 Well, in WHM it picks up the module and has the correct value. It's the folder which worries me. Here's a pic:
http://kwix-host.com/images/Capture.PNG
krakjoe November 17th, 2007, 14:44 what do you mean it worries you ?? it looks right to me .... does loadavg show in get_loaded_extensions( ) array ?
JonnyH November 17th, 2007, 15:06 Nope. Thats the thing.
krakjoe November 17th, 2007, 17:39 Nope. Thats the thing.
ok then, post your ini file, or gimme a login so I can look for you .... preferably the second, if it's a bug I'd really like to know what .....
JonnyH November 18th, 2007, 03:39 PM'd with details.
krakjoe November 18th, 2007, 04:09 no bug, was php.ini config .... carry on ...
To everyone: My recommended values for ini settings are
PHP_INI_ENTRY("loadavg.one", "1.5", PHP_INI_ALL, NULL )
PHP_INI_ENTRY("loadavg.five", "2.0", PHP_INI_ALL, NULL )
PHP_INI_ENTRY("loadavg.ten", "2.5", PHP_INI_ALL, NULL )
dont leave them at under 1 people, you can while you test, but in a production environment these are good ....
Darknight November 18th, 2007, 04:36 PHP_INI_ENTRY("loadavg.one", "1.5", PHP_INI_ALL, NULL )
PHP_INI_ENTRY("loadavg.five", "2.0", PHP_INI_ALL, NULL )
PHP_INI_ENTRY("loadavg.ten", "2.5", PHP_INI_ALL, NULL )
Do you think this setting would be good for a VPS with 1ghz dedicated CPU over 8 cores? (128mhz/core)
Id kinda like to have it so it was only going to kick in if things where really max'ed
And will this work with all php versions?
krakjoe November 18th, 2007, 05:34 Yes, should work with all php versions from 4 upwards ...
Actually, I'm not sure how to answer, I'm not sure if the load average reported will be for your dedicated resources or machine resources, at a guess it's your dedicated resources, in which case the settings I posted should be good ( possibly a little lower ) .... you should probably monitor your load average for a few days, see what occurs normally and under pressure and would probably be beneficial to everyone if you posted your findings here ...
You can always change the settings in load.c again to something that suits better, to do so ...
cd /path/where/you/kep/sources
make clean
make
make install
httpd restart
you MUST make clean if you change settings ....
Mentok November 21st, 2007, 10:25 I'm on debian.. tried it out with settings as 0.0 for everything, made & installed, restarted apache2 and it doesn't work :(
any ideas?
krakjoe November 21st, 2007, 10:59 and it shows up in print_r( get_loaded_extensions( ) ); does it ?? make install does NOT edit php.ini it just installs the shared library in the correct place ....
Mentok November 21st, 2007, 11:20 Didn't do that, but I've done it now (and yes it's listing in get_loaded_extensions()) and it still doesn't work :(.
krakjoe November 21st, 2007, 11:30 send me login details ...
Mentok November 21st, 2007, 11:36 Oh.. my bad. It didn't work before because my load was exactly 0.. if it's over it redirects.
Awesomeness.
krakjoe November 21st, 2007, 11:42 Good ... remember make clean after you change the settings and make and make install again ...
Mentok November 21st, 2007, 11:50 Have done.. cheers.
Darknight November 28th, 2007, 13:22 Ok, Thanks.. Im going to try it out when I upgrade to php5 later today :D looks pretty handy for what Im about to get in to anyway.
Vincenzo August 12th, 2008, 08:23 This is all good stuff, and really glad I joined this forum.
Just a couple of things:
- would it be feasable to make this into an WHM addon, and then we could change values from the WHM backend?
- Is it at all feasable to check and only redirect based on server load by account, so only those causing the issue would be affected? Maybe possible if using PHP as CGI instead of Apache module?
Best wishes,
- Vince
|
|