add ini_file_reader-Chinese.md
parent
63713195ea
commit
deca3d4f35
|
|
@ -0,0 +1,102 @@
|
|||
|
||||
## libfastcommon概述
|
||||
|
||||
```
|
||||
libfastcommon是在github开源的⼀个C函数库。它提供了ini⽂件解析、logger、
|
||||
64位唯⼀整数⽣成器、字符串处理、socket封装、对象池、skiplist、
|
||||
定时任务调度器、时间轮等等。接下来主要介绍下ini⽂件解析ini_file_reader。
|
||||
```
|
||||
|
||||
## ini_file_reader的主要特点:
|
||||
|
||||
### 1、⽀持section
|
||||
```
|
||||
例如: [workers]
|
||||
```
|
||||
|
||||
### 2、⼀个配置项可以出现多次
|
||||
```
|
||||
通过iniGetValuesEx或者iniGetValues获取。例如:
|
||||
tracker_server = ip1
|
||||
tracker_server = ip2
|
||||
```
|
||||
|
||||
### 3、 #include指令包含其他配置⽂件
|
||||
```
|
||||
可以包含本地⽂件,也可以包含URL(目前仅⽀持HTTP)
|
||||
```
|
||||
|
||||
### 4、 #@function指令⽀持标注
|
||||
|
||||
```
|
||||
配置项的取值为扩展(外部)动态库的返回值
|
||||
V1.39⽀持三个内置标注:
|
||||
I. LOCAL_IP_GET [inner|private] 获取本机IP地址
|
||||
II. SHELL_EXEC <command> 获取命令⾏输出
|
||||
III. REPLACE_VARS 替换%{VARIABLE}格式的变量
|
||||
|
||||
配置⽰例:
|
||||
#@function SHELL_EXEC
|
||||
host = hostname
|
||||
|
||||
#@function LOCAL_IP_GET
|
||||
bind_ip = inner
|
||||
|
||||
#@set encoder_filename=/usr/local/etc/encoder.conf
|
||||
#@set encoder_port = $(grep ^inner_port %{encoder_filename} | awk -F '=' '{print $2;}')
|
||||
|
||||
#@function REPLACE_VARS
|
||||
check_alive_command = /usr/local/lib/libdfscheckalive.so %{encoder_port} 2 30
|
||||
```
|
||||
|
||||
### 5、⽀持简单的流程控制,控制标签包括:
|
||||
|
||||
#### I. 条件判断
|
||||
|
||||
```
|
||||
#@if %{VARIABLE} in [x,y,..]
|
||||
…
|
||||
#@else
|
||||
…
|
||||
#@endif
|
||||
其中#@else指令为可选项。
|
||||
|
||||
#@if指令目前仅⽀持这种格式。
|
||||
VARIABLE包括:
|
||||
1) LOCAL_IP:本机IP
|
||||
2) LOCAL_HOST:通过hostname获得的本机主机名
|
||||
3) #@set指令设置的变量, #@set指令格式:
|
||||
|
||||
#@set VAR = value
|
||||
若要获取shell命令⾏输出, value部分格式为: $(command),例如:
|
||||
#@set os_name = $(uname -a | awk '{print $1;}')
|
||||
|
||||
注: LOCAL_IP⽀持CIDR格式的IP地址,例如: 172.16.12.0/22
|
||||
例如:
|
||||
#@if %{LOCAL_IP} in [10.0.11.89,10.0.11.99,172.16.12.0/22]
|
||||
min_subprocess_number = 4
|
||||
#@else
|
||||
min_subprocess_number = 20
|
||||
#@endif
|
||||
```
|
||||
|
||||
#### II. 计数循环
|
||||
|
||||
```
|
||||
#@for VARIABLE from 0 to 15 step 1
|
||||
…
|
||||
#@endfor
|
||||
|
||||
其中VARIABLE⻓度不超过64位字符,在循环体中通过
|
||||
{$VARIABLE}格式获取其值。 step可以为负数,但不能为0。例如:
|
||||
#@for i from 0 to 15 step 1
|
||||
[section{$i}]
|
||||
subprocess_command = /usr/bin/php xxx {$i}
|
||||
subprocess_number = 1
|
||||
#@endfor
|
||||
```
|
||||
|
||||
```
|
||||
另外, libfastcommon中的部分函数提供了PHP扩展。 github地址:
|
||||
https://github.com/happyfish100/libfastcommon,欢迎⼤家下载使⽤。
|
||||
```
|
||||
Binary file not shown.
|
|
@ -1,9 +1,11 @@
|
|||
# ⽇志⽂件优化PHP扩展函数
|
||||
|
||||
```
|
||||
出于提升性能目的,基于libfastcommon封装的php扩展,提供了函数fastcommon_error_log来替代PHP原⽣的error_log,使⽤fastcommon_file_put_contents替换PHP原⽣的file_put_contents。
|
||||
出于提升性能目的,基于libfastcommon封装的php扩展,提供了函数fastcommon_error_log
|
||||
来替代PHP原⽣的error_log,使⽤fastcommon_file_put_contents替换PHP原⽣的file_put_contents。
|
||||
|
||||
原理很简单,就是⽇志⽂件打开后将其⽂件描述符(或⽂件句柄)持久化,避免每次调⽤error_log或file_put_contents时都执⾏open和close等⽂件操作。
|
||||
原理很简单,就是⽇志⽂件打开后将其⽂件描述符(或⽂件句柄)持久化,避免每次调⽤error_log
|
||||
或file_put_contents时都执⾏open和close等⽂件操作。
|
||||
|
||||
在短字符串的场景下,通过实测fastcommon_file_put_contents⽐file_put_contents性能提升2倍以上。
|
||||
fastcommon_error_log⽐error_log性能提升50%以上。
|
||||
|
|
|
|||
Loading…
Reference in New Issue