Raised This Month: $51 Target: $400
 12% 

PHP script to notify via email when game server(s) are down


Post New Thread Reply   
 
Thread Tools Display Modes
Adjo
Member
Join Date: Dec 2009
Location: UK
Old 12-10-2011 , 10:22   Re: PHP script to notify via email when game server(s) are down
Reply With Quote #11

Quote:
Originally Posted by Nomarky View Post
Thanks Adjo that works great!

One php question though (only just starting to get to grips with php...). Where it says
PHP Code:
 $servers = array(
        
'1:2'                        =>    'some-path-to-the-restart-script',
        
'server.google.de:27015'    =>    'some-path-to-the-restart-script',
        
'vsh.dcsrvdls.com:27015'    =>    'some-path-to-the-restart-script',
        
'127.0.0.1:27017'            =>    'some-path-to-the-restart-script'
    
); 
is there a reason why you can't put
PHP Code:
 '1'                        =>  '2'  =>  'some-path-to-the-restart-script'
Trying to do it that way would give an error like, unexpected equals sign, expected ')' (not 100% sure what the error would be, but it's something along those lines).

Anyways, the server ip and port is the 'key', and the restart script path is the 'value' - the key can be accessed like, foreach($servers as $key), but to access the value, you'd need to do, foreach($servers as $key => $value) - hopefully that made sense, wasn't sure how to explain it.

If you're just starting with PHP, have a look at php.net, there's a lot of helpful documentation there - just goto php.net/function.name (Edit: function.name being the function you're curious about, like, php.net/explode for example)

Last edited by Adjo; 12-10-2011 at 10:25.
Adjo is offline
Nomarky
SourceMod Donor
Join Date: Sep 2007
Old 12-10-2011 , 10:44   Re: PHP script to notify via email when game server(s) are down
Reply With Quote #12

Thanks, I get it now! And thanks for the links, just what I need
Nomarky is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 12-10-2011 , 21:58   Re: PHP script to notify via email when game server(s) are down
Reply With Quote #13

foreach($servers as $value) is the default result. To access the key you'd have to do foreach($servers as $key => $value).

You mixed it;)
__________________
Peace-Maker is offline
Nomarky
SourceMod Donor
Join Date: Sep 2007
Old 12-11-2011 , 16:20   Re: PHP script to notify via email when game server(s) are down
Reply With Quote #14

So this method only works if the process has crashed. If the server has hung with an "Assertion failed" message in console this won't detect that the server has actually crashed and needs restarting, even though HLSW will show it as timed out. Does anyone know of a way to detect this type of crash and automatically restart it?
Nomarky is offline
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 12-13-2011 , 10:25   Re: PHP script to notify via email when game server(s) are down
Reply With Quote #15

It's probably not best to check a servers online status via TCP for various reasons.

Here is a function I whipped up you can stick in that script (remember to add back the retry attempt checks):
PHP Code:
function ServerOnline($ip$port$connect_timeout$timeout)
{
    
$fp = @stream_socket_client("udp://{$ip}:{$port}"$errno$errstr$connect_timeout);
    if(!
is_resource($fp))
        return 
false;
    
    
stream_set_timeout($fp$timeout);
    
    
fwrite($fp"\xFF\xFF\xFF\xFF\x55\xFF\xFF\xFF\xFF");
    
$buffer fread($fp1);
    
fclose($fp);
    
    if(!
strlen($buffer))
        return 
false;
    
    return 
true;

This should work for all Source/GoldSrc servers.

Last edited by hlstriker; 12-13-2011 at 10:26.
hlstriker is offline
MoggieX
Veteran Member
Join Date: Aug 2007
Location: n00bville
Old 12-20-2011 , 05:38   Re: PHP script to notify via email when game server(s) are down
Reply With Quote #16

ola!

Just a quicky to say "thanks", used a mix of the suggestions and while they were updating, I got emails yay!

Matt
__________________
MoggieX is offline
Send a message via Skype™ to MoggieX
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:24.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode