优化PHP插件

启动时,就配置php-fpm配置文件
pull/109/head
Mr Chen 6 years ago
parent cb8e46861d
commit 141009be8e
  1. 46
      plugins/php/index.py

@ -113,7 +113,8 @@ def contentReplace(content, version):
def makeOpenrestyConf(): def makeOpenrestyConf():
if public.isInstalledWeb(): if public.isInstalledWeb():
d_pathinfo = public.getServerDir() + '/openresty/nginx/conf/pathinfo.conf' sdir = public.getServerDir()
d_pathinfo = sdir + '/openresty/nginx/conf/pathinfo.conf'
if not os.path.exists(d_pathinfo): if not os.path.exists(d_pathinfo):
s_pathinfo = getPluginDir() + '/conf/pathinfo.conf' s_pathinfo = getPluginDir() + '/conf/pathinfo.conf'
shutil.copyfile(s_pathinfo, d_pathinfo) shutil.copyfile(s_pathinfo, d_pathinfo)
@ -125,12 +126,21 @@ def makeOpenrestyConf():
tpl = getPluginDir() + '/conf/enable-php.conf' tpl = getPluginDir() + '/conf/enable-php.conf'
tpl_content = public.readFile(tpl) tpl_content = public.readFile(tpl)
for x in range(len(versions)): for x in range(len(versions)):
desc_file = public.getServerDir() + '/openresty/nginx/conf/enable-php-' + \ dfile = sdir + '/openresty/nginx/conf/enable-php-' + versions[x] + '.conf'
versions[x] + '.conf' if not os.path.exists(dfile):
if not os.path.exists(desc_file):
w_content = contentReplace(tpl_content, versions[x]) w_content = contentReplace(tpl_content, versions[x])
public.writeFile(desc_file, w_content) public.writeFile(desc_file, w_content)
#php-fpm status
phpversions = ['53','54','55','56','70','71','72','73','74']
for version in phpversions:
dfile = sdir + '/openresty/nginx/conf/php_status/phpfpm_status_' + version + '.conf'
tpl = getPluginDir() + '/conf/phpfpm_status.conf'
if not os.path.exists(dfile):
content = public.readFile(tpl)
content = contentReplace(content, version)
public.writeFile(dfile, content)
public.restartWeb()
def phpFpmReplace(version): def phpFpmReplace(version):
desc_php_fpm = getServerDir() + '/' + version + '/etc/php-fpm.conf' desc_php_fpm = getServerDir() + '/' + version + '/etc/php-fpm.conf'
@ -384,16 +394,8 @@ def setMaxSize(version):
conf = re.sub(rep, u'\npost_max_size = ' + max + 'M', conf) conf = re.sub(rep, u'\npost_max_size = ' + max + 'M', conf)
public.writeFile(path, conf) public.writeFile(path, conf)
# if public.get_webserver() == 'nginx': msg = public.getInfo('设置PHP-{1}最大上传大小为[{2}MB]!',(version, max,))
# path = web.ctx.session.setupPath + '/nginx/conf/nginx.conf' public.writeLog('插件管理[PHP]', msg)
# conf = public.readFile(path)
# rep = "client_max_body_size\s+([0-9]+)m"
# tmp = re.search(rep, conf).groups()
# if int(tmp[0]) < int(max):
# conf = re.sub(rep, 'client_max_body_size ' + max + 'm', conf)
# public.writeFile(path, conf)
public.writeLog("TYPE_PHP", "PHP_UPLOAD_MAX", (version, max))
return public.returnJson(True, '设置成功!') return public.returnJson(True, '设置成功!')
@ -458,20 +460,22 @@ def setFpmConfig(version):
public.writeFile(file, conf) public.writeFile(file, conf)
reload(version) reload(version)
public.writeLog("TYPE_PHP", 'PHP_CHILDREN', (version, max_children,
start_servers, min_spare_servers, max_spare_servers)) msg = public.getInfo('设置PHP-{1}并发设置,max_children={2},start_servers={3},min_spare_servers={4},max_spare_servers={5}',(version, max_children,
return public.returnJson(True, '设置成功') start_servers, min_spare_servers, max_spare_servers,))
public.writeLog('插件管理[PHP]', msg)
return public.returnJson(True, '设置成功!')
def checkFpmStatusFile(version): def checkFpmStatusFile(version):
if public.isInstalledWeb(): if public.isInstalledWeb():
desc_file = public.getServerDir( sdir = public.getServerDir()
) + '/openresty/nginx/conf/php_status/phpfpm_status_' + version + '.conf' dfile = sdir + '/openresty/nginx/conf/php_status/phpfpm_status_' + version + '.conf'
if not os.path.exists(desc_file): if not os.path.exists(dfile):
tpl = getPluginDir() + '/conf/phpfpm_status.conf' tpl = getPluginDir() + '/conf/phpfpm_status.conf'
content = public.readFile(tpl) content = public.readFile(tpl)
content = contentReplace(content, version) content = contentReplace(content, version)
public.writeFile(desc_file, content) public.writeFile(dfile, content)
public.restartWeb() public.restartWeb()

Loading…
Cancel
Save