php 负载状态和phpinfo改变访问方式

pull/121/head
midoks 3 years ago
parent 620fefb633
commit 789c5d85b5
  1. 4
      README.md
  2. 5
      plugins/php-apt/conf/phpfpm_status.conf
  3. 98
      plugins/php-apt/index.py
  4. 5
      plugins/php-yum/conf/phpfpm_status.conf
  5. 98
      plugins/php-yum/index.py
  6. 109
      plugins/php/index.py

@ -11,7 +11,7 @@
[![Wiki](https://img.shields.io/badge/MW-Wiki-red?style=for-the-badge&logo=wiki)](https://github.com/midoks/mdserver-web/wiki)
* SSH工具
* SSH终端工具
* 面板收藏功能
* 网站子目录绑定
* 网站备份功能
@ -23,6 +23,7 @@
- [兼容性测试报告](/compatibility.md)
### 主要插件介绍
* OpenResty - 轻量级,占有内存少,并发能力强。
* PHP[52-81] - PHP是世界上最好的编程语言。
* MySQL - 一种关系数据库管理系统。
@ -45,7 +46,6 @@ PHP[72-81]支持phpMyAdmin[5.2.0]
```
### 版本更新 0.8.6
* mysql主从配置。
* swap插件[虚拟内存]。

@ -1,5 +0,0 @@
location /phpfpm_status_apt{$PHP_VERSION} {
fastcgi_pass unix:/run/php/php{$PHP_VERSION}-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME \$fastcgi_script_name;
}

@ -123,9 +123,6 @@ def makeOpConf(version):
dst_dir = sdir + '/web_conf/php'
dst_dir_conf = sdir + '/web_conf/php/conf'
dst_dir_status = sdir + '/web_conf/php/status'
if not os.path.exists(dst_dir):
mw.execShell('mkdir -p ' + dst_dir)
if not os.path.exists(dst_dir_conf):
mw.execShell('mkdir -p ' + dst_dir_conf)
@ -144,14 +141,6 @@ def makeOpConf(version):
w_content = contentReplace(tpl_content, version)
mw.writeFile(dfile, w_content)
# php-fpm status
dfile = sdir + '/web_conf/php/status/phpfpm_status_apt' + version + '.conf'
tpl = getPluginDir() + '/conf/phpfpm_status.conf'
if not os.path.exists(dfile):
content = mw.readFile(tpl)
content = contentReplace(content, version)
mw.writeFile(dfile, content)
def phpFpmWwwReplace(version):
service_php_fpm_dir = getServerDir() + '/' + version + '/fpm/pool.d'
@ -460,43 +449,47 @@ def setFpmConfig(version):
return mw.returnJson(True, '设置成功!')
def checkFpmStatusFile(version):
if not mw.isInstalledWeb():
return False
dfile = mw.getServerDir() + '/web_conf/php/status/phpfpm_status_apt' + \
version + '.conf'
if not os.path.exists(dfile):
tpl = getPluginDir() + '/conf/phpfpm_status.conf'
content = mw.readFile(tpl)
content = contentReplace(content, version)
mw.writeFile(dfile, content)
mw.restartWeb()
return True
def getFpmAddress(version):
fpm_address = '/run/php/php{}-fpm.sock'.format(version)
php_fpm_file = getFpmConfFile(version)
try:
content = readFile(php_fpm_file)
tmp = re.findall(r"listen\s*=\s*(.+)", content)
if not tmp:
return fpm_address
if tmp[0].find('sock') != -1:
return fpm_address
if tmp[0].find(':') != -1:
listen_tmp = tmp[0].split(':')
if bind:
fpm_address = (listen_tmp[0], int(listen_tmp[1]))
else:
fpm_address = ('127.0.0.1', int(listen_tmp[1]))
else:
fpm_address = ('127.0.0.1', int(tmp[0]))
return fpm_address
except:
return fpm_address
def getFpmStatus(version):
checkFpmStatusFile(version)
stat = status(version)
if stat == 'stop':
return mw.returnJson(False, 'PHP[' + version + ']未启动!!!')
sock_file = getFpmAddress(version)
try:
url = 'http://' + mw.getHostAddr() + '/phpfpm_status_apt' + version + '?json'
result = mw.httpGet(url, 1)
data = json.loads(result)
fTime = time.localtime(int(data['start time']))
data['start time'] = time.strftime('%Y-%m-%d %H:%M:%S', fTime)
sock_data = mw.requestFcgiPHP(
sock_file, '/phpfpm_status_apt' + version + '?json')
except Exception as e:
url = 'http://127.0.0.1/phpfpm_status_apt' + version + '?json'
result = mw.httpGet(url, 1)
return mw.returnJson(False, str(e))
# print(data)
result = str(sock_data, encoding='utf-8')
data = json.loads(result)
fTime = time.localtime(int(data['start time']))
data['start time'] = time.strftime('%Y-%m-%d %H:%M:%S', fTime)
except Exception as e:
data = {}
return mw.returnJson(True, "OK", data)
@ -533,33 +526,24 @@ def setDisableFunc(version):
return mw.returnJson(True, '设置成功!')
def checkPhpinfoFile(v):
sdir = mw.getServerDir()
dfile = sdir + '/web_conf/php/status/phpinfo_' + v + '.conf'
tpl = getPluginDir() + '/conf/phpinfo.conf'
content = mw.readFile(tpl)
content = contentReplace(content, v)
mw.writeFile(dfile, content)
mw.restartWeb()
def getPhpinfo(v):
checkPhpinfoFile(v)
sPath = mw.getRootDir() + '/phpinfo/' + v
mw.execShell("rm -rf " + mw.getRootDir() + '/phpinfo')
mw.execShell("mkdir -p " + sPath)
mw.writeFile(sPath + '/phpinfo.php', '<?php phpinfo(); ?>')
url = 'http://127.0.0.1/' + v + '/phpinfo.php'
phpinfo = mw.httpGet(url)
def getPhpinfo(version):
stat = status(version)
if stat == 'stop':
return mw.returnJson(False, 'PHP[' + version + ']未启动!!!')
sock_file = getFpmAddress(version)
root_dir = mw.getRootDir() + '/phpinfo'
mw.execShell("rm -rf " + root_dir)
mw.execShell("mkdir -p " + root_dir)
mw.writeFile(root_dir + '/phpinfo.php', '<?php phpinfo(); ?>')
sock_data = mw.requestFcgiPHP(sock_file, '/phpinfo.php', root_dir)
os.system("rm -rf " + mw.getRootDir() + '/phpinfo')
phpinfo = str(sock_data, encoding='utf-8')
return phpinfo
def get_php_info(args):
if not mw.isInstalledWeb():
return "openresty is not running!!!"
inputVer = args['version']
version = inputVer[0] + '.' + inputVer[1]
return getPhpinfo(version)

@ -1,5 +0,0 @@
location /phpfpm_status_yum{$PHP_VERSION} {
fastcgi_pass unix:/var/opt/remi/php{$PHP_VERSION}/run/php-fpm/www.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME \$fastcgi_script_name;
}

@ -119,9 +119,6 @@ def makeOpenrestyConf(version):
dst_dir = sdir + '/web_conf/php'
dst_dir_conf = sdir + '/web_conf/php/conf'
dst_dir_status = sdir + '/web_conf/php/status'
if not os.path.exists(dst_dir):
mw.execShell('mkdir -p ' + dst_dir)
if not os.path.exists(dst_dir_conf):
mw.execShell('mkdir -p ' + dst_dir_conf)
@ -140,14 +137,6 @@ def makeOpenrestyConf(version):
w_content = contentReplace(tpl_content, version)
mw.writeFile(dfile, w_content)
# php-fpm status
dfile = sdir + '/web_conf/php/status/phpfpm_status_yum' + version + '.conf'
tpl = getPluginDir() + '/conf/phpfpm_status.conf'
if not os.path.exists(dfile):
content = mw.readFile(tpl)
content = contentReplace(content, version)
mw.writeFile(dfile, content)
def phpFpmWwwReplace(version):
service_php_fpm_dir = getServerDir() + '/php' + version + '/php-fpm.d/'
@ -175,7 +164,6 @@ def getFpmConfFile(version):
def deleteConfList(version):
sdir = mw.getServerDir()
enable_conf = sdir + '/web_conf/php/conf/enable-php-yum' + version + '.conf'
status_conf = sdir + '/web_conf/php/status/phpfpm_status_yum' + version + '.conf'
clist = (status_conf, enable_conf)
for f in clist:
@ -460,42 +448,46 @@ def setFpmConfig(version):
return mw.returnJson(True, '设置成功!')
def checkFpmStatusFile(version):
if not mw.isInstalledWeb():
return False
dfile = getServerDir() + '/nginx/conf/php_status/phpfpm_status_yum' + version + '.conf'
if not os.path.exists(dfile):
tpl = getPluginDir() + '/conf/phpfpm_status.conf'
content = mw.readFile(tpl)
content = contentReplace(content, version)
mw.writeFile(dfile, content)
mw.restartWeb()
return True
def getFpmAddress(version):
fpm_address = '/var/opt/remi/php{}/run/php-fpm/www.sock'.format(version)
php_fpm_file = getFpmConfFile(version)
try:
content = readFile(php_fpm_file)
tmp = re.findall(r"listen\s*=\s*(.+)", content)
if not tmp:
return fpm_address
if tmp[0].find('sock') != -1:
return fpm_address
if tmp[0].find(':') != -1:
listen_tmp = tmp[0].split(':')
if bind:
fpm_address = (listen_tmp[0], int(listen_tmp[1]))
else:
fpm_address = ('127.0.0.1', int(listen_tmp[1]))
else:
fpm_address = ('127.0.0.1', int(tmp[0]))
return fpm_address
except:
return fpm_address
def getFpmStatus(version):
checkFpmStatusFile(version)
stat = status(version)
if stat == 'stop':
return mw.returnJson(False, 'PHP[' + version + ']未启动!!!')
sock_file = getFpmAddress(version)
try:
url = 'http://' + mw.getHostAddr() + '/phpfpm_status_yum' + version + '?json'
result = mw.httpGet(url, 1)
data = json.loads(result)
fTime = time.localtime(int(data['start time']))
data['start time'] = time.strftime('%Y-%m-%d %H:%M:%S', fTime)
sock_data = mw.requestFcgiPHP(
sock_file, '/phpfpm_status_yum' + version + '?json')
except Exception as e:
url = 'http://127.0.0.1/phpfpm_status_yum' + version + '?json'
result = mw.httpGet(url, 1)
return mw.returnJson(False, str(e))
# print(data)
result = str(sock_data, encoding='utf-8')
data = json.loads(result)
fTime = time.localtime(int(data['start time']))
data['start time'] = time.strftime('%Y-%m-%d %H:%M:%S', fTime)
except Exception as e:
data = {}
return mw.returnJson(True, "OK", data)
@ -532,32 +524,24 @@ def setDisableFunc(version):
return mw.returnJson(True, '设置成功!')
def checkPhpinfoFile(v):
sdir = mw.getServerDir()
dfile = sdir + '/web_conf/php/status/phpinfo_' + v + '.conf'
tpl = getPluginDir() + '/conf/phpinfo.conf'
content = mw.readFile(tpl)
content = contentReplace(content, v)
mw.writeFile(dfile, content)
mw.restartWeb()
def getPhpinfo(v):
checkPhpinfoFile(v)
sPath = mw.getRootDir() + '/phpinfo/' + v
mw.execShell("rm -rf " + mw.getRootDir() + '/phpinfo')
mw.execShell("mkdir -p " + sPath)
mw.writeFile(sPath + '/phpinfo.php', '<?php phpinfo(); ?>')
url = 'http://127.0.0.1/' + v + '/phpinfo.php'
phpinfo = mw.httpGet(url)
def getPhpinfo(version):
stat = status(version)
if stat == 'stop':
return mw.returnJson(False, 'PHP[' + version + ']未启动!!!')
sock_file = getFpmAddress(version)
root_dir = mw.getRootDir() + '/phpinfo'
mw.execShell("rm -rf " + root_dir)
mw.execShell("mkdir -p " + root_dir)
mw.writeFile(root_dir + '/phpinfo.php', '<?php phpinfo(); ?>')
sock_data = mw.requestFcgiPHP(sock_file, '/phpinfo.php', root_dir)
os.system("rm -rf " + mw.getRootDir() + '/phpinfo')
phpinfo = str(sock_data, encoding='utf-8')
return phpinfo
def get_php_info(args):
if not mw.isInstalledWeb():
return "openresty is not running!!!"
return getPhpinfo(args['version'])

@ -162,13 +162,13 @@ def makeOpenrestyConf():
mw.writeFile(dfile, w_content)
# php-fpm status
for version in phpversions:
dfile = sdir + '/web_conf/php/status/phpfpm_status_' + version + '.conf'
tpl = getPluginDir() + '/conf/phpfpm_status.conf'
if not os.path.exists(dfile):
content = mw.readFile(tpl)
content = contentReplace(content, version)
mw.writeFile(dfile, content)
# for version in phpversions:
# dfile = sdir + '/web_conf/php/status/phpfpm_status_' + version + '.conf'
# tpl = getPluginDir() + '/conf/phpfpm_status.conf'
# if not os.path.exists(dfile):
# content = mw.readFile(tpl)
# content = contentReplace(content, version)
# mw.writeFile(dfile, content)
def phpPrependFile(version):
@ -554,44 +554,64 @@ def setFpmConfig(version):
return mw.returnJson(True, '设置成功!')
def checkFpmStatusFile(version):
if not mw.isInstalledWeb():
return False
# def checkFpmStatusFile(version):
# if not mw.isInstalledWeb():
# return False
# dfile = getServerDir() + '/nginx/conf/php_status/phpfpm_status_' + version + '.conf'
# if not os.path.exists(dfile):
# tpl = getPluginDir() + '/conf/phpfpm_status.conf'
# content = mw.readFile(tpl)
# content = contentReplace(content, version)
# mw.writeFile(dfile, content)
# mw.restartWeb()
# return True
dfile = getServerDir() + '/nginx/conf/php_status/phpfpm_status_' + version + '.conf'
if not os.path.exists(dfile):
tpl = getPluginDir() + '/conf/phpfpm_status.conf'
content = mw.readFile(tpl)
content = contentReplace(content, version)
mw.writeFile(dfile, content)
mw.restartWeb()
return True
def getFpmAddress(version):
fpm_address = '/tmp/php-cgi-{}.sock'.format(version)
php_fpm_file = getFpmConfFile(version)
try:
content = readFile(php_fpm_file)
tmp = re.findall(r"listen\s*=\s*(.+)", content)
if not tmp:
return fpm_address
if tmp[0].find('sock') != -1:
return fpm_address
if tmp[0].find(':') != -1:
listen_tmp = tmp[0].split(':')
if bind:
fpm_address = (listen_tmp[0], int(listen_tmp[1]))
else:
fpm_address = ('127.0.0.1', int(listen_tmp[1]))
else:
fpm_address = ('127.0.0.1', int(tmp[0]))
return fpm_address
except:
return fpm_address
def getFpmStatus(version):
if version == '52':
return mw.returnJson(False, 'PHP[' + version + ']不支持!!!')
checkFpmStatusFile(version)
stat = status(version)
if stat == 'stop':
return mw.returnJson(False, 'PHP[' + version + ']未启动!!!')
sock_file = getFpmAddress(version)
try:
url = 'http://' + mw.getHostAddr() + '/phpfpm_status_' + version + '?json'
result = mw.httpGet(url, 1)
data = json.loads(result)
fTime = time.localtime(int(data['start time']))
data['start time'] = time.strftime('%Y-%m-%d %H:%M:%S', fTime)
sock_data = mw.requestFcgiPHP(
sock_file, '/phpfpm_status_' + version + '?json')
except Exception as e:
url = 'http://127.0.0.1/phpfpm_status_' + version + '?json'
result = mw.httpGet(url, 1)
return mw.returnJson(False, str(e))
# print(data)
result = str(sock_data, encoding='utf-8')
data = json.loads(result)
fTime = time.localtime(int(data['start time']))
data['start time'] = time.strftime('%Y-%m-%d %H:%M:%S', fTime)
except Exception as e:
data = {}
return mw.returnJson(True, "OK", data)
@ -628,33 +648,24 @@ def setDisableFunc(version):
return mw.returnJson(True, '设置成功!')
def checkPhpinfoFile(v):
sdir = mw.getServerDir()
dfile = sdir + '/web_conf/php/status/phpinfo_' + v + '.conf'
tpl = getPluginDir() + '/conf/phpinfo.conf'
content = mw.readFile(tpl)
content = contentReplace(content, v)
mw.writeFile(dfile, content)
mw.restartWeb()
def getPhpinfo(version):
stat = status(version)
if stat == 'stop':
return mw.returnJson(False, 'PHP[' + version + ']未启动!!!')
def getPhpinfo(v):
checkPhpinfoFile(v)
sPath = mw.getRootDir() + '/phpinfo/' + v
sock_file = getFpmAddress(version)
root_dir = mw.getRootDir() + '/phpinfo'
mw.execShell("rm -rf " + mw.getRootDir() + '/phpinfo')
mw.execShell("mkdir -p " + sPath)
mw.writeFile(sPath + '/phpinfo.php', '<?php phpinfo(); ?>')
url = 'http://127.0.0.1/' + v + '/phpinfo.php'
phpinfo = mw.httpGet(url)
mw.execShell("rm -rf " + root_dir)
mw.execShell("mkdir -p " + root_dir)
mw.writeFile(root_dir + '/phpinfo.php', '<?php phpinfo(); ?>')
sock_data = mw.requestFcgiPHP(sock_file, '/phpinfo.php', root_dir)
os.system("rm -rf " + mw.getRootDir() + '/phpinfo')
phpinfo = str(sock_data, encoding='utf-8')
return phpinfo
def get_php_info(args):
if not mw.isInstalledWeb():
return "openresty is not running!!!"
return getPhpinfo(args['version'])

Loading…
Cancel
Save