tgp1994 Posted August 6, 2009 Share Posted August 6, 2009 Hi there everyone, I'm trying to make a server pinger that pings my Garry's Mod game server to see if it's up. This shouldn't be very difficult, but it is for me since I'm new. As an added bonus, does anyone know if I can have it put text into a picture, with player info and such? Quote Link to comment Share on other sites More sharing options...
jonsjava Posted August 6, 2009 Share Posted August 6, 2009 first: a pinger. simple, but I use extra PHP PEAR libraries to do it (faster, and bypasses running commands on the local server). I can give you the basics of it, but if you can't install/don't have PEAR and Net_ping, my scripts won't do you much good. second: you'll need to use PHP-GD to modify graphics. Quote Link to comment Share on other sites More sharing options...
ldougherty Posted August 6, 2009 Share Posted August 6, 2009 Or if you prefer you can just use the system ping command using EXEC in your code. http://us3.php.net/manual/en/function.exec.php You can run any server command in your script via EXEC Quote Link to comment Share on other sites More sharing options...
tgp1994 Posted August 6, 2009 Author Share Posted August 6, 2009 Wow, thanks for the fast replies, guys. You should all hang out in the IRC room. Anyways, does anyone have any examples, preferably small ones? If the GD image library is too much, then I won't bother. And does anyone know why I have to do this image verification everytime I make a topic or reply? Quote Link to comment Share on other sites More sharing options...
jonsjava Posted August 6, 2009 Share Posted August 6, 2009 Or if you prefer you can just use the system ping command using EXEC in your code. http://us3.php.net/manual/en/function.exec.php You can run any server command in your script via EXEC if your host allows the web user to exec or shell_exec scripts. As for the image verification, I'm guessing because you're new here. Quote Link to comment Share on other sites More sharing options...
tgp1994 Posted August 6, 2009 Author Share Posted August 6, 2009 Well, I am my own host, so anything goes by me. So do you have an example for this? Quote Link to comment Share on other sites More sharing options...
ldougherty Posted August 6, 2009 Share Posted August 6, 2009 echo "<pre>"; system ("ping -c4 $host"); system("killall ping");// kill all ping processes in case there are some stalled ones or use echo 'ping' to execute ping without shell echo "</pre>"; the 4 is how many ping requests to send and $host is the IP address/domain you wish to ping. Quote Link to comment Share on other sites More sharing options...
tgp1994 Posted August 6, 2009 Author Share Posted August 6, 2009 And can I get it to echo the result of each individual ping? Quote Link to comment Share on other sites More sharing options...
ldougherty Posted August 6, 2009 Share Posted August 6, 2009 I've actually run this exact code on 3 different servers and on two the output was generated line by line where as on the 3rd the output was generated all at once. I'm honestly not sure of the difference other than possibly OS but everything else matched up exactly the same. Quote Link to comment Share on other sites More sharing options...
tgp1994 Posted August 6, 2009 Author Share Posted August 6, 2009 Ya, I don't see it return anything. So does anyone have a working example? Quote Link to comment Share on other sites More sharing options...
tgp1994 Posted August 6, 2009 Author Share Posted August 6, 2009 And just so we know, I'm running Windows Server 2003 incase that makes a difference. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted August 6, 2009 Share Posted August 6, 2009 the ping command is different in windows. ping google.com -s4 -w200 that will ping google 4 times, with a 200ms timeout Quote Link to comment Share on other sites More sharing options...
jonsjava Posted August 6, 2009 Share Posted August 6, 2009 if this server is your own server, it should be a breeze getting PEAR installed, and then installing Net_ping go to the PHP folder (for me, it's C:\PHP5) you will see a go-pear.bat file. run it you will be prompted with a few questions. defaults are the safe road. Now, you can go to the command line, and go to pear folder (for me, it's C:\PHP5\PEAR) type this in pear install Net_ping now, you're set up with Net::ping here's my ping script: <?php header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past // Number of times to Ping the host $count = $_GET['count']; // Host we are pinging $url = $_GET['ip']; // This is the Pear Net_Ping class call require_once "Net/Ping.php"; $ping = Net_Ping::factory(); $ping->setArgs(array('count'=>1,'timeout'=>1)); // Set variables. I know I don't have to, but why not do things right? $transmitted = 0; $received = 0; $loss = 0; $text = ""; for ($i=0; $i< $count; $i++){ //Send ping request $output = $ping->ping($url); // If the ping returns no errors, lets parse the results. if (isset($output->_transmitted)){ // Raw data, if you want to see what it returned from the ping ( full text) $raw = $output->_raw_data; // This is the transmitted count. if it's zero, that means it fa iled in transmission. We shouldn't get a zero, but this is to handle that instan ce $trans = (string)$output->_transmitted; // if it successfully transmitted, lets parse the result, and ad d it up. if ($trans == 1){ $transmitted++; $received += (string)$output->_received; if ((string)$output->_loss != 0){ $loss++; $text .="."; } else{ $text .="#"; } } else{ $transmitted++; $loss++; $text .="."; } } } echo <<<EOF <?xml version="1.0" encoding="utf-8" ?> <PingResults Version='1.0'> <PingResult Host='$url' Text='$text' Trasmitted='$transmitted' Received= '$received' Loss='$loss' /> </PingResults> EOF; ?> it outputs XML. you can change that to suit your needs. Quote Link to comment Share on other sites More sharing options...
tgp1994 Posted August 6, 2009 Author Share Posted August 6, 2009 Thank you, but the PEAR installation will most likely different for me since: 1.PHP installation failed when I was using IIS for unknown reasons, so: 2.I got WAMP, works awesomely Thus, I think somehow I will mess up with the installation of PEAR, unless it comes with WAMP. EDIT: Ok, I installed pear, and I navigate to the folder you suggested, (except a little different since I use WAMP), then it says: 'pear' is not a recognized internal or external command. And there doesn't seem to be a pear.exe file in there, anyways. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted August 6, 2009 Share Posted August 6, 2009 I'm downloading WAMP to check now Quote Link to comment Share on other sites More sharing options...
tgp1994 Posted August 6, 2009 Author Share Posted August 6, 2009 Lol ok, thanks. I edited the above post, btw. EDIT: Nevermind, turns out I had to go to the PHP directory rather than PHP\PEAR. Downloading the thing now. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted August 6, 2009 Share Posted August 6, 2009 holy crud. they have most of the mainstream PEAR packages. just go to %wamp_install_folder%\php in the command prompt, and run the command I stated earlier. Quote Link to comment Share on other sites More sharing options...
tgp1994 Posted August 6, 2009 Author Share Posted August 6, 2009 Lol I'm not sure if this is needed, but I think I may have to restart Apache. Otherwise, would you happen to know why it's saying: Fatal error: require_once() [function.require]: Failed opening required 'Net/Ping.php' (include_path='.;C:\php5\pear') in C:\wamp\www\serverchecker\index.php on line 9 Quote Link to comment Share on other sites More sharing options...
jonsjava Posted August 6, 2009 Share Posted August 6, 2009 lol. yup. you've gotta restart apache so it can reload the php.ini file Quote Link to comment Share on other sites More sharing options...
tgp1994 Posted August 6, 2009 Author Share Posted August 6, 2009 Weird, still gives me an error. Is there something I need to manually change in the php.ini file? EDIT: Ok, I uncommented the include_path option and put in the PEAR directory, but now the error reads: Notice: Undefined index: count in C:\wamp\www\serverchecker\index.php on line 5 Notice: Undefined index: ip in C:\wamp\www\serverchecker\index.php on line 7 Quote Link to comment Share on other sites More sharing options...
jonsjava Posted August 6, 2009 Share Posted August 6, 2009 find the line in the php.ini that says ;include_path=".;c:\php\includes" and change it to include_path = ".;c:\\WAMP\\php\\includes;c:\\WAMP\\php\\PEAR" notice that I removed the semi-colon at the beginning, and added pear to the list. change the paths to fit your install Quote Link to comment Share on other sites More sharing options...
tgp1994 Posted August 6, 2009 Author Share Posted August 6, 2009 Ok, but there actually isn't an includes directory in my php installation. Is that a problem? EDIT: And here's what I think the line should look like now: include_path = ".;c:\\WAMP\\bin\\php\\php5.2.9-2\\includes;c:\\WAMP\\bin\php\\php5.2.9-2\\PEAR" Does it seem right? Cause I still got the same two errors. Remeber, I still don't have an includes directory. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted August 6, 2009 Share Posted August 6, 2009 you don't need one. you can remove that one. just make sure that your include_path has c:\\wamp\php\pear This will be my last post for a while. time to go home for the night. Quote Link to comment Share on other sites More sharing options...
tgp1994 Posted August 6, 2009 Author Share Posted August 6, 2009 Ya, that still doesn't seem to change the two errors above, unless the script is correct. If anyone else would like to pitch in, that would be great. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted August 7, 2009 Share Posted August 7, 2009 ok. back. try doing this: include_path = ".;c:\WAMP\bin\php\php5.2.9-2\PEAR" changing the path, respectivly Quote Link to comment 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.