Skip to content

Commit e160863

Browse files
committed
PHP7优化
1 parent a2f1fef commit e160863

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

Lua-Script/sort/selectionSort.lua

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--
2+
-- Created by IntelliJ IDEA.
3+
-- User: Administrator
4+
-- Date: 2017/6/14
5+
-- Time: 10:08
6+
-- To change this template use File | Settings | File Templates.
7+
--首先在未排序序列中找到最小元素,存放到排序序列的起始位置 再从剩余未排序元素中继续寻找最小元素,然后放到已排序序列的末尾。 重复第二步,直到所有元素均排序完毕。
8+
local function selectionSort(arr)
9+
for i = 1,#arr-1 do
10+
local idx = i
11+
-- 迭代剩下的元素,寻找最小的元素
12+
for j = i+1,#arr do
13+
if arr[j] < arr[idx] then
14+
idx = j
15+
end
16+
end
17+
--
18+
arr[i],arr[idx]= arr[idx],arr[i]
19+
end
20+
end
21+
22+
local list = {
23+
-81, -93, -36.85, -53, -31, 79, 45.94, 36, 94, -95.03, 11, 56, 23, -39,
24+
14, 1, -20.1, -21, 91, 31, 91, -23, 36.5, 44, 82, -30, 51, 96, 64, -41
25+
}
26+
27+
selectionSort(list)
28+
print(table.concat( list, ", "))
29+
print(#list)
30+
for i = 1 ,#list do
31+
print(i)
32+
end
33+
34+

Nginx/nginx-parameter-config.md

+25
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,31 @@
3535
* soft nofile 65535
3636
* hard nofile 65535
3737
```
38+
## PHP7优化
39+
+ [让PHP7达到最高性能的几个Tips](http://www.laruence.com/2015/12/04/3086.html)
40+
+ [Nginx+PHP7 安装及配置](http://tchuairen.blog.51cto.com/3848118/1771597/)
41+
+ 启用Zend Opcache
42+
```bash
43+
zend_extension=opcache.so
44+
opcache.enable=1
45+
opcache.enable_cli=1
46+
```
47+
+ 使用新的编译器,使用新一点的编译器, 推荐GCC 4.8以上, 因为只有GCC 4.8以上PHP才会开启Global Register for opline and execute_data支持, 这个会带来5%左右的性能提升
48+
+ 开启HugePages,然后开启Opcache的huge_code_pages
49+
+ sfd `sudo sysctl vm.nr_hugepages=512`
50+
+ 分配512个预留的大页内存
51+
```bash
52+
$ cat /proc/meminfo | grep Huge
53+
AnonHugePages: 106496 kB
54+
HugePages_Total: 512
55+
HugePages_Free: 504
56+
HugePages_Rsvd: 27
57+
HugePages_Surp: 0
58+
Hugepagesize: 2048 kB
59+
```
60+
+ 然后在php.ini中加入,`opcache.huge_code_pages=1`
61+
+ 开启Opcache File Cache,`opcache.file_cache=/tmp`
62+
+ 启用Zend Opcache
3863
## PHP-FPM优化
3964
+ rlimit_files
4065
+ rlimit_files

README.md

+27-1
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,33 @@
488488
```
489489
+ Lua面向对象1
490490
+ Lua面向对象1
491-
+ Lua面向对象3 更新中...
491+
+ Lua面向对象3 更新中...
492+
+ Lua 排序算法
493+
+ [Lua 排序算法 - 选择排序](https://www.openresty.com.cn/ms2008-select-sort.html#section-1)
494+
+ 选择排序
495+
```lua
496+
local function selectionSort(arr)
497+
for i = 1,#arr-1 do
498+
local idx = i
499+
-- 迭代剩下的元素,寻找最小的元素
500+
for j = i+1,#arr do
501+
if arr[j] < arr[idx] then
502+
idx = j
503+
end
504+
end
505+
--
506+
arr[i],arr[idx]= arr[idx],arr[i]
507+
end
508+
end
509+
510+
local list = {
511+
-81, -93, -36.85, -53, -31, 79, 45.94, 36, 94, -95.03, 11, 56, 23, -39,
512+
14, 1, -20.1, -21, 91, 31, 91, -23, 36.5, 44, 82, -30, 51, 96, 64, -41
513+
}
514+
515+
selectionSort(list)
516+
print(table.concat( list, ", "))
517+
```
492518
#### 控制结构
493519
+ [if-elseif-end 语句](https://github.com/Tinywan/Lua-Nginx-Redis/blob/master/Lua-Script/chapter-one/if-else-example.lua)
494520
+ [for 语句](https://github.com/Tinywan/Lua-Nginx-Redis/blob/master/Lua-Script/chapter-one/for-example.lua)

0 commit comments

Comments
 (0)