import os
import time
def get_size(start_path = ''):
total_size = 0
for dirpath, dirnames, filenames in os.walk(start_path):
for f in filenames:
fp = os.path.join(dirpath, f)
total_size += os.path.getsize(fp)
return total_size
def wirte_to_file(path,value):
print (value)
f = open(path, 'w')
f.write(str(value))
f.close()
path = '/var/www/html/xx/app'
while True:
currentSize = get_size(start_path=path)
with open("sizelog", 'r') as f:
perSize = f.read()
if int(perSize) != currentSize:
wirte_to_file('sizelog', currentSize)
os.system("php /var/www/html/xx/artisan swoole:server stop")
os.system("nohup php /var/www/html/xx/artisan swoole:server start &")
print('not same')
print (perSize)
time.sleep(5)
自己优化一下就好了