Home php教程 php手册 配置文件在正式服务器上的部署

配置文件在正式服务器上的部署

Jun 06, 2016 pm 07:37 PM
server formal deploy Configuration file

配置文件在正式服务器上的部署。 从文件服务器下载配置文件,备份并替换本地的配置文件,将配置文件压缩成zip格式 无 ?phpheader("Content-Type:text/html;charset=utf-8");include 'tz.php';/** * 执行配置文件的压缩 * Created by PhpStorm. * User: saint

配置文件在正式服务器上的部署。
从文件服务器下载配置文件,备份并替换本地的配置文件,将配置文件压缩成zip格式

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

<?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();

Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to configure Dnsmasq as a DHCP relay server How to configure Dnsmasq as a DHCP relay server Mar 21, 2024 am 08:50 AM

The role of a DHCP relay is to forward received DHCP packets to another DHCP server on the network, even if the two servers are on different subnets. By using a DHCP relay, you can deploy a centralized DHCP server in the network center and use it to dynamically assign IP addresses to all network subnets/VLANs. Dnsmasq is a commonly used DNS and DHCP protocol server that can be configured as a DHCP relay server to help manage dynamic host configurations in the network. In this article, we will show you how to configure dnsmasq as a DHCP relay server. Content Topics: Network Topology Configuring Static IP Addresses on a DHCP Relay D on a Centralized DHCP Server

Best Practice Guide for Building IP Proxy Servers with PHP Best Practice Guide for Building IP Proxy Servers with PHP Mar 11, 2024 am 08:36 AM

In network data transmission, IP proxy servers play an important role, helping users hide their real IP addresses, protect privacy, and improve access speeds. In this article, we will introduce the best practice guide on how to build an IP proxy server with PHP and provide specific code examples. What is an IP proxy server? An IP proxy server is an intermediate server located between the user and the target server. It acts as a transfer station between the user and the target server, forwarding the user's requests and responses. By using an IP proxy server

What should I do if I can't enter the game when the epic server is offline? Solution to why Epic cannot enter the game offline What should I do if I can't enter the game when the epic server is offline? Solution to why Epic cannot enter the game offline Mar 13, 2024 pm 04:40 PM

What should I do if I can’t enter the game when the epic server is offline? This problem must have been encountered by many friends. When this prompt appears, the genuine game cannot be started. This problem is usually caused by interference from the network and security software. So how should it be solved? The editor of this issue will explain I would like to share the solution with you, I hope today’s software tutorial can help you solve the problem. What to do if the epic server cannot enter the game when it is offline: 1. It may be interfered by security software. Close the game platform and security software and then restart. 2. The second is that the network fluctuates too much. Try restarting the router to see if it works. If the conditions are OK, you can try to use the 5g mobile network to operate. 3. Then there may be more

Yolov10: Detailed explanation, deployment and application all in one place! Yolov10: Detailed explanation, deployment and application all in one place! Jun 07, 2024 pm 12:05 PM

1. Introduction Over the past few years, YOLOs have become the dominant paradigm in the field of real-time object detection due to its effective balance between computational cost and detection performance. Researchers have explored YOLO's architectural design, optimization goals, data expansion strategies, etc., and have made significant progress. At the same time, relying on non-maximum suppression (NMS) for post-processing hinders end-to-end deployment of YOLO and adversely affects inference latency. In YOLOs, the design of various components lacks comprehensive and thorough inspection, resulting in significant computational redundancy and limiting the capabilities of the model. It offers suboptimal efficiency, and relatively large potential for performance improvement. In this work, the goal is to further improve the performance efficiency boundary of YOLO from both post-processing and model architecture. to this end

Where is the win10 user profile? How to set the user profile in Win10 Where is the win10 user profile? How to set the user profile in Win10 Jun 25, 2024 pm 05:55 PM

Recently, many Win10 system users want to change the user profile, but they don’t know how to do it. This article will show you how to set the user profile in Win10 system! How to set up user profile in Win10 1. First, press the "Win+I" keys to open the settings interface, and click to enter the "System" settings. 2. Then, in the opened interface, click "About" on the left, then find and click "Advanced System Settings". 3. Then, in the pop-up window, switch to the "" option bar and click "User Configuration" below.

How to install PHP FFmpeg extension on server? How to install PHP FFmpeg extension on server? Mar 28, 2024 pm 02:39 PM

How to install PHPFFmpeg extension on server? Installing the PHPFFmpeg extension on the server can help us process audio and video files in PHP projects and implement functions such as encoding, decoding, editing, and processing of audio and video files. This article will introduce how to install the PHPFFmpeg extension on the server, as well as specific code examples. First, we need to ensure that PHP and FFmpeg are installed on the server. If FFmpeg is not installed, you can follow the steps below to install FFmpe

Install Helm on Ubuntu Install Helm on Ubuntu Mar 20, 2024 pm 06:41 PM

Helm is an important component of Kubernetes that simplifies the deployment of Kubernetes applications by bundling configuration files into a package called HelmChart. This approach makes updating a single configuration file more convenient than modifying multiple files. With Helm, users can easily deploy Kubernetes applications, simplifying the entire deployment process and improving efficiency. In this guide, I'll cover different ways to implement Helm on Ubuntu. Please note: The commands in the following guide apply to Ubuntu 22.04 as well as all Ubuntu versions and Debian-based distributions. These commands are tested and should work correctly on your system. in U

Detailed explanation of the advantages and utility of Golang server Detailed explanation of the advantages and utility of Golang server Mar 20, 2024 pm 01:51 PM

Golang is an open source programming language developed by Google. It is efficient, fast and powerful and is widely used in cloud computing, network programming, big data processing and other fields. As a strongly typed, static language, Golang has many advantages when building server-side applications. This article will analyze the advantages and utility of Golang server in detail, and illustrate its power through specific code examples. 1. The high-performance Golang compiler can compile the code into local code

See all articles