body_back.php
3.6 KB
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
162
163
164
165
166
167
168
169
170
<?php
// 这个是提交脚本
\Co\run(function(){
while (1){
$body = db()->first("select * from `bodies` limit 1 ");
if(!$body || $body['lists_id']>300000000){
echo "执行完成\n";
break;
}
$d = 0;
$len = \Swlib\SaberGM::post('http://172.19.0.5:9527?id='.$body['lists_id'],['body'=>$body['text_html']])->getBody()->getContents();
if(is_numeric($len)&&$len){
$d = db()->delete('bodies',['lists_id'=>$body['lists_id']]);
}
_echo('成功 '.$body['lists_id'].' == '.$d.' == '.$len);
}
});
// 这个是读取备份内容
\Co\run(function(){
$body = \Swlib\SaberGM::get('http://172.19.0.5:9527?id='.$body['lists_id'])->getBody()->getContents();
});
exit();
?>
这里是2个文件哦
------------------------------------------------------------------------------
<?php
/**
* 这个是一个http服务,邮件服务的body内容太大了,把body内容备份到其他服务器,
* 其他服务器放入这个代码 并运行
* 走内网 提交数据
* post 为提交
* get 为获取
*
*/
ini_set("memory_limit", "512M");
// 关闭错误提示 其实这个可有可无 显示了错误也不会输出到前端
//ini_set("display_errors","off");
// 错误级别
error_reporting(E_ALL);
// 时区设置
date_default_timezone_set('Asia/Shanghai');
// 定义 root 目录
define('root_path', __DIR__);
/**
* 服务
* @author:dc
* @time 2025/4/18 15:44
* Class mmd_serv
*/
class mmd_serv
{
/**
* 这个是http服务,对外的
* @var Swoole\Http\Server
*/
private $server;
public function __construct()
{
$this->init_http();
}
/**
* 前端请求处理
* @param \Swoole\Http\Request $request
* @param \Swoole\Http\Response $response
* @author:dc
* @time 2025/4/30 15:42
*/
public function request(\Swoole\Http\Request $request, \Swoole\Http\Response $response)
{
$len = 0;
if($request->server['request_uri']){
}
// print_r($request->get);
$id = intval($request->get['id']??0);
$path = root_path.'/mail/'.($id%10000).'/'.$id.'.log';
$m = strtoupper($request->getMethod());
// get 获取数据
if($m=='GET'){
$len = file_get_contents($path);
}
// 删除数据
elseif($m == 'DELETE'){
$len = unlink($path)?1:0;
}
elseif($m == 'POST'){
$body = $request->post['body']??'';
if($id && $body){
if(!is_dir(dirname($path))){
mkdir(dirname($path),0775,true);
}
$len = file_put_contents($path,$body);
}
}
$response->header("Content-Type", 'text/html; charset=UTF-8');
$response->end($len);
}
/**
* 初始
* @author:dc
* @time 2025/4/30 14:50
*/
private function init_http()
{
// 实例一个服务
$this->server = new Swoole\Http\Server("0.0.0.0", 9527);
// 服务设置
$this->server->set([
// 'open_http2_protocol' => true, // http2协议
// 'log_file' => __DIR__.'/error.log',
// 'log_level' => 0,
'package_max_length' => 20 * 1024 * 1024, // 可以post多大数据
// 'daemonize' => true
]);
// 前端请求时
$this->server->on('request', [$this, 'request']);
}
/**
* 启动http 服务
* @author:dc
* @time 2025/5/10 21:57
*/
public function start()
{
$this->server->start();
}
}
(new mmd_serv())->start();