0

[PHP]DirectAdmin PHP5.6安装swoole

客户要求安装swoole,也不知道什么鬼用途。记一下笔记。

yum install gcc make autoconf pcre -y
cd ~
wget http://pecl.php.net/get/swoole-1.10.5.tgz
tar -zxvf swoole-1.10.5.tgz
cd swoole-1.10.5
export PHP_PREFIX="/usr/local"
$PHP_PREFIX/php56/bin/phpize
./configure --with-php-config=$PHP_PREFIX/php56/bin/php-config
make -j 2
make install

echo "extension=swoole.so" >> /usr/local/php56/lib/php.conf.d/20-custom.ini
service httpd restart
php -i | grep "swoole"
0

[PHP]根据User Agent判断是否搜索引擎蜘蛛

/* 判断搜索引擎 摘自Discuz x3.2 */
function checkrobot($useragent=''){
  static $kw_spiders = array('bot', 'crawl', 'spider' ,'slurp', 'sohu-search', 'lycos', 'robozilla');
  static $kw_browsers = array('msie', 'netscape', 'opera', 'konqueror', 'mozilla');

  $useragent = strtolower(empty($useragent) ? $_SERVER['HTTP_USER_AGENT'] : $useragent);
  if(strpos($useragent, 'http://') === false && dstrpos($useragent, $kw_browsers)) return false;
  if(dstrpos($useragent, $kw_spiders)) return true;
  return false;
}
function dstrpos($string, $arr, $returnvalue = false) {
  if(empty($string)) return false;
  foreach((array)$arr as $v) {
    if(strpos($string, $v) !== false) {
      $return = $returnvalue ? $v : true;
      return $return;
    }
  }
  return false;
}

Continue Reading

0

[PHP]PHP获取服务器IP输出为数组

用PHP执行ifconfig获得Linux服务器IP并输出为数组,下面是代码:

function getServerIp(){ //用ifconfig读取服务器IP并输出为数组
		$ss = exec('/sbin/ifconfig | sed -n \'s/^ *.*addr:\\([0-9.]\\{7,\\}\\) .*$/\\1/p\'',$arr);
		return $arr; 
		}
$ips=getServerIp();
foreach($ips as $k=>$v){//过滤IP
	if(substr($v,0,3)=='127' || substr($v,0,3)=='10.' || substr($v,0,7)=='192.168' || substr($v,0,6)=='172.16'){
		unset($ips[$k]);
	}
}
shuffle($ips);//重新排序
print_r($ips);