mirror of
https://github.com/midoks/mdserver-web.git
synced 2026-10-18 23:45:52 +08:00
php 负载状态和phpinfo改变访问方式
This commit is contained in:
@@ -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;
|
||||
}
|
||||
+41
-57
@@ -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)
|
||||
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(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)
|
||||
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(version):
|
||||
stat = status(version)
|
||||
if stat == 'stop':
|
||||
return mw.returnJson(False, 'PHP[' + version + ']未启动!!!')
|
||||
|
||||
sock_file = getFpmAddress(version)
|
||||
root_dir = mw.getRootDir() + '/phpinfo'
|
||||
|
||||
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)
|
||||
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'])
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user