WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Ping a Server and run a command to fix it if it is down
Categories : PHP, Errors and Logging, Regexps Update Picture
Antonio Leal
Date : Aug 13th 2003
Grade : 3 of 5 (graded 3 times)
Viewed : 8323
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Antonio Leal
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 


Autor: Antonio Leal Elizondo 12/Ago/03
e-mail: invasor@hotmail.com
This script pings a machine and checks if it's alive or not.
It can run a command in case the machine is not answering

<?php
// Variables
//-------------------------
   
$unix      1; //Put 1 here if you are using a UNIX machine
   
$windows   0; //Put 1 here if you are using a Windown machine


   
$unix = (bool) $unix;
   
$win  = (bool)  $windows;

   
$count= 3;                            // Number of times to ping
   
$host   = "177.17.31.165";             // IP of the remote server
   
$find = "Tiempo de espera agotado";   // String to look for
   
$shell= "pwd";                          // Command to execute if the machine does not answer.
   
$findUnix="0 packets received";


     
// Replaced nonvalued characters     
     
$host= preg_replace ("/[^A-Za-z0-9.]/","",$host);
      echo(
"Resultados: ");
       
     
//Check the IP
     
if ($unix==1){
         
$comm="ping -t $count $host";
         
$res=shell_exec($comm);
      }else{
         
$comm="ping -n $count $host";
         
$res=shell_exec($comm);
      }
     
//  system("killall ping");// Kill all pings in case they exist.
      //echo $res;

     
$flag= strstr($res,$findUnix);
     
$long=strlen($flag);
     if (
$long<>0){
       echo
"\n An error has occured at $host\n ";
       echo   
date("D F Y  h:i a");
       echo
"\n Executng auxiliary command \n ";
       
$res=shell_exec($shell);
        echo
$res;
      }else{
       echo
"\n There are no problems with $host \n";
      echo   
date("D F Y  h:i a"). "\n" ;
     }
?>




DB Connection Function with error handling and email failure notices
Categories : PHP, MySQL, Errors and Logging, Databases, Errors and Logging
Check if a file exists on a remote FTP server with PHP
Categories : PHP, FTP, Regexps
Avoiding or Detecting high bit characters in a string. Useful when you want to create a valid RSS feed
Categories : PHP, Strings, Unicode, Regexps, Rich Site Summary (RSS)
Simple way to replace a variable value in a .conf (.ini) file using a webbrowser - the first stage of a complete universal configuration editor
Categories : PHP, Regexps, Code Editors, Filesystem
ereg -- Regular expression match
Categories : PHP, PHP Functions, Regexps
Intelligent 404 Handler
Categories : PHP, Errors and Logging
Gets the browser and OS from the $_SERVER['http_user_agent'] variable in PHP
Categories : PHP, HTTP, Regexps
BBCode Formatting String
Categories : PHP, HTML, Regexps, Arrays
Tag content retrieval from websites with preg_match
Categories : PHP, Regexps, Arrays, HTML and PHP
I need a trim function/regexp that will trim all " " from the ends of a string.
Categories : Regexps, PHP, Strings
This script is a contact form between users of a website (kinda like the PM function on the forums)
Categories : PHP, Databases, MySQL, Regexps
Form input return conformance
Categories : HTML and PHP, PHP, Regexps
Simple PHP program which calls other PHP program you can pass the variables to other PHP program : by Raju
Categories : PHP, PHP Options and Info, Regexps, Program Execution
A simple function to prevent undefined $_POST/$_GET/$_SESSION variable errors
Categories : PHP, Variables, Errors and Logging
How to build a search query for any N number of words in a search string
Categories : PHP, Regexps, Search Engines, Search