-
Notifications
You must be signed in to change notification settings - Fork 0
/
php.html
533 lines (347 loc) · 13.7 KB
/
php.html
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
<!DOCTYPE html>
<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js"><!--<![endif]-->
<head>
<meta charset="utf-8">
<title>
php - 搁羽念风
</title>
<meta name="author" content="">
<meta name="description" content="">
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="asset/css/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
<link href="atom.xml" rel="alternate" title="搁羽念风" type="application/atom+xml">
<script src="asset/js/modernizr-2.0.js"></script>
<script src="asset/js/jquery.min.js"></script>
<script src="asset/highlightjs/highlight.pack.js"></script>
<link href="asset/highlightjs/styles/solarized_light.css" media="screen, projection" rel="stylesheet" type="text/css">
<script>hljs.initHighlightingOnLoad();</script>
<style type="text/css">
.cat-children-p{ padding: 6px 0px;}
.hljs{background: none;}
</style>
<script type="text/javascript">
var isAddSildbar = true;
</script>
<script src="asset/js/octopress.js" type="text/javascript"></script>
</head>
<script type="text/javascript">
//链接新开窗口
function addBlankTargetForLinks () {
$('a[href^="http"]').each(function(){
$(this).attr('target', '_blank');
});
}
$(document).ready(function(event) {
addBlankTargetForLinks();
});
</script>
<body >
<header role="banner"><hgroup>
<h1><a href="index.html">搁羽念风</a></h1>
<h2></h2>
</hgroup>
</header>
<nav role="navigation"><ul class="subscription" data-subscription="rss">
<li><a href="atom.xml" rel="subscribe-rss" title="subscribe via RSS">RSS</a></li>
</ul>
<form action="http://google.com/search" method="get">
<fieldset role="search">
<input type="hidden" name="q" value="site:" />
<input class="search" type="text" name="q" results="0" placeholder="Search"/>
</fieldset>
</form>
<ul class="main-navigation">
<li id=""><a target="self" href="index.html">Home</a></li>
<li id=""><a target="_self" href="archives.html">Archives</a></li>
</ul>
</nav>
<div id="main">
<div id="content">
<div class="blog-index">
<article>
<header>
<h1 class="entry-title"><a href="15548815336055.html">php相关函数</a></h1>
<p class="meta"><time datetime="2019-04-10T15:32:13+08:00"
pubdate data-updated="true">2019/4/10</time></p>
</header>
<div class="entry-content">
<h3 id="toc_0">umask() 函数,改变umask值,使进程权限保持一致</h3>
<pre class="line-numbers"><code class="language-text">编写linux守护进程的时候,需要设置umask 这个值,用户权限屏蔽位,
当用户创建目录或者文件的时候,会有一个预设的权限 r=4,w=2,x=1
目录的预设权限是:0777 drwxrwxrwx
文件的预设权限为: 0666 -rw-rw-rw-
用这个权限减去 umask的权限,就是新建的目录或者文件的实际权限了
umask 默认值为 0022
新建文件夹权限为 0777 - 0022 = 0755
新建文件权限为 0666 - 0022 = 0644
</code></pre>
<h3 id="toc_1">pcntl_fork() 函数,在进程的当前位置产生分支(子进程)</h3>
<p>在当前进程的当前位置 产生分支(子进程), 都从fork位置继续执行, <br/>
成功时<br/>
父进程执行过程中得到的fork返回值为子进程号,子进程得到的是0<br/>
失败时<br/>
父进程将会返回 -1,不会创建子进程,并引发一个php错误</p>
<h3 id="toc_2">posix_setsid() 新建一个session终端,脱离原有终端的控制</h3>
<p>成功时<br/>
返回 session_id<br/>
失败时<br/>
返回 -1</p>
<h3 id="toc_3">php_sapi_name() 判断运行时环境</h3>
<h3 id="toc_4">extension_loaded() 检查一个扩展是否已经加载</h3>
<h3 id="toc_5">cli_set_process_title()</h3>
<p>为进程设定title <br/>
成功时<br/>
返回 true<br/>
失败时<br/>
返回 false</p>
</div>
</article>
<article>
<header>
<h1 class="entry-title"><a href="15540894210258.html">php 生成uuid的统一类</a></h1>
<p class="meta"><time datetime="2019-04-01T11:30:21+08:00"
pubdate data-updated="true">2019/4/1</time></p>
</header>
<div class="entry-content">
<pre class="line-numbers"><code class="language-php"><?php
class UUID {
public static function v3($namespace, $name) {
if(!self::is_valid($namespace)) return false;
// Get hexadecimal components of namespace
$nhex = str_replace(array('-','{','}'), '', $namespace);
// Binary Value
$nstr = '';
// Convert Namespace UUID to bits
for($i = 0; $i < strlen($nhex); $i+=2) {
$nstr .= chr(hexdec($nhex[$i].$nhex[$i+1]));
}
// Calculate hash value
$hash = md5($nstr . $name);
return sprintf('%08s-%04s-%04x-%04x-%12s',
// 32 bits for "time_low"
substr($hash, 0, 8),
// 16 bits for "time_mid"
substr($hash, 8, 4),
// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 3
(hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x3000,
// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
(hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
// 48 bits for "node"
substr($hash, 20, 12)
);
}
public static function v4() {
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
// 32 bits for "time_low"
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
// 16 bits for "time_mid"
mt_rand(0, 0xffff),
// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 4
mt_rand(0, 0x0fff) | 0x4000,
// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
mt_rand(0, 0x3fff) | 0x8000,
// 48 bits for "node"
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
);
}
public static function v5($namespace, $name) {
if(!self::is_valid($namespace)) return false;
// Get hexadecimal components of namespace
$nhex = str_replace(array('-','{','}'), '', $namespace);
// Binary Value
$nstr = '';
// Convert Namespace UUID to bits
for($i = 0; $i < strlen($nhex); $i+=2) {
$nstr .= chr(hexdec($nhex[$i].$nhex[$i+1]));
}
// Calculate hash value
$hash = sha1($nstr . $name);
return sprintf('%08s-%04s-%04x-%04x-%12s',
// 32 bits for "time_low"
substr($hash, 0, 8),
// 16 bits for "time_mid"
substr($hash, 8, 4),
// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 5
(hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x5000,
// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
(hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
// 48 bits for "node"
substr($hash, 20, 12)
);
}
public static function is_valid($uuid) {
return preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?'.
'[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/i', $uuid) === 1;
}
}
// Usage
// Named-based UUID.
$v3uuid = UUID::v3('1546058f-5a25-4334-85ae-e68f2a44bbaf', 'SomeRandomString');
$v5uuid = UUID::v5('1546058f-5a25-4334-85ae-e68f2a44bbaf', 'SomeRandomString');
// Pseudo-random UUID
$v4uuid = UUID::v4();
?>
</code></pre>
</div>
</article>
<article>
<header>
<h1 class="entry-title"><a href="15524706279073.html">信号管理,当接收到关闭信号的时候,处理完最后的数据再关闭</a></h1>
<p class="meta"><time datetime="2019-03-13T17:50:27+08:00"
pubdate data-updated="true">2019/3/13</time></p>
</header>
<div class="entry-content">
<pre class="line-numbers"><code class="language-text"><?php
declare(ticks = 1);
function sig_handler($sig) {
switch($sig) {
case SIGINT:
error_log("接收信号SIGINT");
exit(1);
case SIGTERM:
error_log("接收信号SIGTERM");
exit(1);
case SIGHUP:
error_log("接收信号SIGHUP");
exit(1);
}
}
pcntl_signal(SIGINT, "sig_handler");
pcntl_signal(SIGTERM, "sig_handler");
pcntl_signal(SIGHUP, "sig_handler");
while (true) {
error_log("哈哈哈");
sleep(3);
}
</code></pre>
</div>
</article>
<article>
<header>
<h1 class="entry-title"><a href="15514283796439.html">类mysql order 多值排序</a></h1>
<p class="meta"><time datetime="2019-03-01T16:19:39+08:00"
pubdate data-updated="true">2019/3/1</time></p>
</header>
<div class="entry-content">
<pre class="line-numbers"><code class="language-php">
function orderBy($data, $orders) {
$sorts = [
'desc' => SORT_DESC,
'asc' => SORT_ASC
];
$tmp = [];
foreach ($orders as $order => $sort) {
$cols = array_column($data, $order);
if(!isset($sorts[$sort])) {
return $data;
}
$tmp[] = $cols;
$tmp[] = $sorts[$sort];
}
$tmp[] = $data;
call_user_func_array('array_multisort', $tmp);
// array_multisort($cols, $sorts[$sort], $data);
print_r($data);
return $data;
}
$data = [
['score'=>2, 'date'=>'2015'],
['score'=>2, 'date'=>'2014'],
['score'=>1, 'date'=>'2017'],
['score'=>3, 'date'=>'2014'],
];
$order = [
'score' => 'asc',
'date' => 'desc'
];
$order = orderBy($data, $order);
</code></pre>
</div>
</article>
<div class="pagination">
<a href="archives.html">Blog Archives</a>
</div>
</div>
<aside class="sidebar">
<section>
<h1>Categories</h1>
<ul id="recent_posts">
<li class="post">
<a href="linux.html"><strong>linux (3)</strong></a>
</li>
<li class="post">
<a href="%E6%95%B0%E6%8D%AE%E5%BA%93.html"><strong>数据库 (6)</strong></a>
<p class="cat-children-p">
<a href="redis.html">redis (3)</a>
<a href="clickhouse.html">clickhouse (3)</a>
</p>
</li>
<li class="post">
<a href="%E4%B8%AD%E9%97%B4%E4%BB%B6.html"><strong>中间件 (6)</strong></a>
<p class="cat-children-p">
<a href="%E6%B6%88%E6%81%AF%E9%98%9F%E5%88%97.html">消息队列 (4)</a>
<a href="%E6%95%B0%E6%8D%AE%E6%B8%85%E6%B4%97.html">数据清洗 (1)</a>
<a href="%E7%9B%91%E6%8E%A7%E6%8A%A5%E8%AD%A6.html">监控报警 (1)</a>
</p>
</li>
<li class="post">
<a href="%E8%AF%AD%E8%A8%80.html"><strong>语言 (9)</strong></a>
<p class="cat-children-p">
<a href="lua.html">lua (1)</a>
<a href="php.html">php (4)</a>
<a href="golang.html">golang (4)</a>
</p>
</li>
<li class="post">
<a href="%E5%B7%A5%E5%85%B7.html"><strong>工具 (2)</strong></a>
</li>
<li class="post">
<a href="%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F.html"><strong>设计模式 (3)</strong></a>
</li>
<li class="post">
<a href="%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0.html"><strong>读书笔记 (1)</strong></a>
</li>
</ul>
</section>
<section>
<h1>Recent Posts</h1>
<ul id="recent_posts">
<li class="post">
<a href="15589244025963.html">大数据架构</a>
</li>
<li class="post">
<a href="15586915631306.html">对lua携程做超时时间</a>
</li>
<li class="post">
<a href="15586915348117.html"></a>
</li>
<li class="post">
<a href="15586818694083.html">nsq简介</a>
</li>
<li class="post">
<a href="15585794233066.html">mac 安装nsq</a>
</li>
</ul>
</section>
</aside> </div></div>
<footer role="contentinfo"><p>
Copyright © 2014 - -
<span class="credit">Powered by <a target="_blank" href="http://www.mweb.im">MWeb</a> Theme by <a href="http://octopress.org">Octopress</a></span>
</p>
</footer>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script><script type="text/x-mathjax-config">MathJax.Hub.Config({TeX: { equationNumbers: { autoNumber: "AMS" } }});</script>
</body>
</html>