配置文件在正式服务器上的部署。 从文件服务器下载配置文件,备份并替换本地的配置文件,将配置文件压缩成zip格式 无 ?phpheader("Content-Type:text/html;charset=utf-8");include 'tz.php';/** * 执行配置文件的压缩 * Created by PhpStorm. * User: saint
配置文件在正式服务器上的部署。
<?php
header("Content-Type:text/html;charset=utf-8");
include 'tz.php';
/**
* 执行配置文件的压缩
* Created by PhpStorm.
* User: saint
* Date: 2015/3/18
* Time: 14:25
*/
if(!defined("SYSTEM_PATH")) define("SYSTEM_PATH", '/data/wwwroot/static/webroot');
class Compress
{
/**
* @var array 这里是需要处理的配置文件
*/
public $cfg_files = array(
'DEMO1Config.json', #
);
/**
* @var string 文件服务器地址
*/
public $file_server = '';
public $cfg_path = '';
public $temp_path = '';
public $zip_file = '';
/**
* 环境初始化
*/
public function _InitEnv()
{
$this->cfg_path = SYSTEM_PATH . '/metafile';
if(false == (is_dir( $this->cfg_path) && is_writable($this->cfg_path))) {
throw new Exception('配置目录不存在或者不可写');
}
$this->temp_path = SYSTEM_PATH . '/tmp';
if(false == (is_dir($this->temp_path) && is_writable($this->temp_path))) {
throw new Exception('临时配置目录不存在或者不可写');
}
if(function_exists('file_get_contents') == false) {
throw new Exception('file_get_contents函数已禁用');
}
if(function_exists('file_put_contents') == false) {
throw new Exception('file_put_contents函数已禁用');
}
if(class_exists('ZipArchive') == false) {
throw new Exception('找不到ZipArchive');
}
}
public function downloadFiles()
{
$start = microtime(true);
try {
$this->_InitEnv();
} catch (Exception $e) {
echo $e->getMessage();
exit;
}
$file_array = array();
// 依次从服务器上下载配置文件
foreach($this->cfg_files as $filename) {
$tmp_file = $this->temp_path . '/' . $filename;
$remote_file = $this->file_server . '/' . $filename;
// 检查本地是否存在临时文件,如果有,则检查这个文件本地文件是否一致
$is_download = true;
if(is_file($tmp_file)) {
if(hash_file('sha256', $tmp_file) == hash_file('sha256', $remote_file)) {
$is_download = false;
}
}
if($is_download) {
$contents = file_get_contents($remote_file);
file_put_contents($tmp_file, $contents);
}
$file_array[] = $tmp_file;
}
// 对配置文件进行压缩
try {
$this->compressFiles();
} catch (Exception $e) {
echo $e->getMessage();
exit;
}
$limit = microtime(true) - $start;
echo '<p>生成压缩文件成功,本次耗时:' . $limit . 's</p>';
echo '<p>开始替换原来的配置文件</p>';
$this->replaceFiles();
// 插入数据库
echo '<p>替换完毕</p>
<div class="aritcle_card">
<a class="aritcle_card_img" href="/xiazai/code/8889">
<img src="https://img.php.cn/upload/webcode/000/000/004/175711680870388.jpg" alt="易森网络企业版">
</a>
<div class="aritcle_card_info">
<a href="/xiazai/code/8889">易森网络企业版</a>
<p>如果您是新用户,请直接将本程序的所有文件上传在任一文件夹下,Rewrite 目录下放置了伪静态规则和筛选器,可将规则添加进IIS,即可正常使用,不用进行任何设置;(可修改图片等)默认的管理员用户名、密码和验证码都是:yeesen系统默认关闭,请上传后登陆后台点击“核心管理”里操作如下:进入“配置管理”中的&ld</p>
<div class="">
<img src="/static/images/card_xiazai.png" alt="易森网络企业版">
<span>0</span>
</div>
</div>
<a href="/xiazai/code/8889" class="aritcle_card_btn">
<span>查看详情</span>
<img src="/static/images/cardxiayige-3.png" alt="易森网络企业版">
</a>
</div>
';
}
// 替换原来的文件
public function replaceFiles()
{
// 打开配置目录,创建备份目录
chdir($this->cfg_path);
$backup_dir = 'cfg_bak_' . date('Ymd');
if(is_dir($backup_dir)) {
rmdir($backup_dir);
}
mkdir($backup_dir, 0777);
array_push($this->cfg_files, $this->zip_file);
foreach($this->cfg_files as $file_name) {
$dst_file = $backup_dir . '/' . $file_name;
if(is_file($file_name)) {
copy($file_name, $dst_file);
}
$new_file = $this->temp_path . '/' . $file_name;
copy($new_file, $file_name);
}
}
/**
* 执行压缩文件
* @param $file_array
* @throws Exception
*/
public function compressFiles()
{
chdir($this->temp_path);
$this->zip_file = 'cfg_' . date(('Ymd')) . '.zip';
$zipClass = new ZipArchive();
$fp = $zipClass->open($this->zip_file, ZipArchive::CREATE);
if($fp === true) {
foreach($this->cfg_files as $file_name) {
$zipClass->addFile($file_name);
}
} else {
throw new Exception('压缩失败:' . $fp);
}
$zipClass->close();
}
}
$obj = new Compress();
$obj->downloadFiles();
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号