配置文件在正式服务器上的部署。 从文件服务器下载配置文件,备份并替换本地的配置文件,将配置文件压缩成zip格式 无 ?phpheader("Content-Type:text/html;charset=utf-8");include 'tz.php';/** * 执行配置文件的压缩 * Created by PhpStorm. * User: saint
配置文件在正式服务器上的部署。
从文件服务器下载配置文件,备份并替换本地的配置文件,将配置文件压缩成zip格式
<?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>'; } // 替换原来的文件 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();
성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사
R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 최고의 그래픽 설정
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
어 ass 신 크리드 그림자 : 조개 수수께끼 솔루션
2 몇 주 전ByDDD
R.E.P.O. 아무도들을 수없는 경우 오디오를 수정하는 방법
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25 : Myrise에서 모든 것을 잠금 해제하는 방법
4 몇 주 전By尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

VSCode Windows 64비트 다운로드
Microsoft에서 출시한 강력한 무료 IDE 편집기

SublimeText3 Linux 새 버전
SublimeText3 Linux 최신 버전

ZendStudio 13.5.1 맥
강력한 PHP 통합 개발 환경

SublimeText3 영어 버전
권장 사항: Win 버전, 코드 프롬프트 지원!

Atom Editor Mac 버전 다운로드
가장 인기 있는 오픈 소스 편집기
