Category Archives: PHP Code

PHP Compile from Source

Compile PHP on 64bit CentOS:

./configure --prefix=/etc/php --bindir=/usr/bin --includedir=/usr/include --libdir=/usr/lib64 --mandir=/usr/share/man --sysconfdir=/etc/php --with-apxs2=/usr/sbin/apxs --with-config-file-path=/etc --with-mysql=/usr/bin/ --with-libdir=lib64 --with-pear --with-mcrypt --enable-mbstring

Monitor a web server using PHP

function check($host, $find)
{
	$fp = fsockopen($host, 80, $errno, $errstr, 10);
	if (!$fp)
	{
		echo "$errstr ($errno)\n";
	}
	else
	{
		$header = "GET / HTTP/1.1\r\n";
		$header .= "Host: $host\r\n";
		$header .= "Connection: close\r\n\r\n";
		fputs($fp, $header);
		while (!feof($fp))
		{
			$str .= fgets($fp, 1024);
		}
		fclose($fp);
		return (strpos($str, $find) !== false);
	}
}

function alert($host)
{
	mail('youremail@gmail.com', 'Monitoring', $host.' down');
}

$host = 'www.monkeyguild.org';
$find = 'Monkeyninja Code';
if (!check($host, $find)) alert($host);