Tegic Blog

升级 swoole 版本

写了一个脚本,方便使用

#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

Swoole_Version='4.4.4'
runPath=/root

extPath()
{
  case "${version}" in 
  '70')
  extFile='/www/server/php/70/lib/php/extensions/no-debug-non-zts-20151012/swoole.so'
  ;;
  '71')
  extFile='/www/server/php/71/lib/php/extensions/no-debug-non-zts-20160303/swoole.so'
  ;;
  '72')
  extFile='/www/server/php/72/lib/php/extensions/no-debug-non-zts-20170718/swoole.so'
  ;;
  '73')
  extFile='/www/server/php/73/lib/php/extensions/no-debug-non-zts-20180731/swoole.so'
  ;;
esac
}


Install_Swoole()
{
  public_file=/www/server/panel/install/public.sh
  : '
  if [ ! -f $public_file ];then
    wget -O $public_file http://download.bt.cn/install/public.sh -T 5;
  fi
  . $public_file
  '
  
  extPath
  if [ ! -f "${extFile}" ];then
  	wget https://github.com/swoole/swoole-src/archive/v$Swoole_Version.tar.gz
  	tar -zxvf v$Swoole_Version.tar.gz
  	cd swoole-src-$Swoole_Version
  	/www/server/php/$version/bin/phpize
		./configure --with-php-config=/www/server/php/$version/bin/php-config --enable-openssl --with-openssl-dir=/usr/local/openssl --enable-sockets
		make && make install
		cd ../
		rm -rf swoole*
		#rm -f v$Swoole_Version*
 	fi

 	if [ ! -f "${extFile}" ];then
 		echo 'error';
 		exit 0;
 	fi
 	
 	echo -e "\n[swoole]\nextension = swoole.so\nswoole.use_shortname = 'Off'\n" >> /www/server/php/$version/etc/php.ini

 	service php-fpm-$version reload
}



Uninstall_Swoole()
{
  extPath
	sed -i '/swoole/d' /www/server/php/$version/etc/php.ini
  rm -f ${extFile}
	service php-fpm-$version reload
	echo '==============================================='
	echo 'successful!'
}

actionType=$1
version=$2
vphp=${version:0:1}.${version:1:1}
if [ "$actionType" == 'install' ];then
	Install_Swoole
elif [ "$actionType" == 'uninstall' ];then
	Uninstall_Swoole
fi

食用方法

#将帖子附件压缩包中的 shell 脚本移动到 /www/server/panel/install目录下
cd /www/server/panel/install
chmod +x swoole4.sh
bash swoole4.sh install 72

#如果已安装 swoole 扩展,请先卸载 bash swoole4.sh uninstall 72