Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
SkyAPM
SkyAPM-php-sdk
提交
f791f418
S
SkyAPM-php-sdk
项目概览
SkyAPM
/
SkyAPM-php-sdk
通知
14
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SkyAPM-php-sdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f791f418
编写于
7月 24, 2019
作者:
H
heyanlong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
peer
上级
bd38f65f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
58 addition
and
4 deletion
+58
-4
skywalking.c
skywalking.c
+58
-4
未找到文件。
skywalking.c
浏览文件 @
f791f418
...
...
@@ -36,6 +36,7 @@
#include "ext/standard/php_var.h"
#include "ext/pdo/php_pdo_driver.h"
#include "ext/mysqli/php_mysqli_structs.h"
#include "ext/pcre/php_pcre.h"
#include "ext/standard/basic_functions.h"
#include "ext/standard/php_math.h"
...
...
@@ -120,6 +121,36 @@ const zend_function_entry class_skywalking[] = {
PHP_FE_END
};
static
char
*
pcre_match
(
char
*
pattern
,
int
len
,
char
*
subject
)
{
pcre_cache_entry
*
cache
;
zval
*
result
=
(
zval
*
)
emalloc
(
sizeof
(
zval
));
bzero
(
result
,
sizeof
(
zval
));
zval
*
subpats
=
(
zval
*
)
emalloc
(
sizeof
(
zval
));
bzero
(
subpats
,
sizeof
(
zval
));
char
*
ret
=
NULL
;
zend_string
*
pattern_str
=
zend_string_init
(
pattern
,
len
,
0
);
if
((
cache
=
pcre_get_compiled_regex_cache
(
pattern_str
))
!=
NULL
)
{
php_pcre_match_impl
(
cache
,
subject
,
strlen
(
subject
),
result
,
subpats
,
0
,
0
,
0
,
0
);
zval
*
match
=
NULL
;
if
(
Z_LVAL_P
(
result
)
>
0
&&
Z_TYPE_P
(
subpats
)
==
IS_ARRAY
)
{
zval
*
value
=
zend_hash_index_find
(
Z_ARRVAL_P
(
subpats
),
1
);
if
(
value
!=
NULL
)
{
match
=
value
;
if
(
Z_TYPE_P
(
match
)
==
IS_STRING
)
{
ret
=
estrdup
(
Z_STRVAL_P
(
match
));
}
}
}
}
zend_string_free
(
pattern_str
);
efree
(
result
);
zval_dtor
(
subpats
);
efree
(
subpats
);
return
ret
;
}
ZEND_API
void
sky_execute_ex
(
zend_execute_data
*
execute_data
)
{
...
...
@@ -330,6 +361,15 @@ ZEND_API void sky_execute_internal(zend_execute_data *execute_data, zval *return
if
(
dbh
->
data_source
!=
NULL
&&
db_type
[
0
]
!=
'\0'
)
{
add_assoc_string
(
&
tags
,
"db.data_source"
,
(
char
*
)
dbh
->
data_source
);
char
*
host
=
pcre_match
(
"(host=([^;
\\
s]+))"
,
sizeof
(
"(host=([^;
\\
s]+))"
)
-
1
,
(
char
*
)
dbh
->
data_source
);
char
*
port
=
pcre_match
(
"(port=([^;
\\
s]+))"
,
sizeof
(
"(port=([^;
\\
s]+))"
)
-
1
,
(
char
*
)
dbh
->
data_source
);
if
(
host
!=
NULL
&&
port
!=
NULL
)
{
peer
=
(
char
*
)
emalloc
(
strlen
(
host
)
+
10
);
bzero
(
peer
,
strlen
(
host
)
+
10
);
sprintf
(
peer
,
"%s:%s"
,
host
,
port
);
}
if
(
host
!=
NULL
)
efree
(
host
);
if
(
port
!=
NULL
)
efree
(
port
);
}
}
}
else
if
(
strcmp
(
class_name
,
"PDOStatement"
)
==
0
)
{
...
...
@@ -345,6 +385,15 @@ ZEND_API void sky_execute_internal(zend_execute_data *execute_data, zval *return
if
(
db_type
[
0
]
!=
'\0'
&&
stmt
->
dbh
!=
NULL
&&
stmt
->
dbh
->
data_source
!=
NULL
)
{
add_assoc_string
(
&
tags
,
"db.data_source"
,
(
char
*
)
stmt
->
dbh
->
data_source
);
char
*
host
=
pcre_match
(
"(host=([^;
\\
s]+))"
,
sizeof
(
"(host=([^;
\\
s]+))"
)
-
1
,
(
char
*
)
stmt
->
dbh
->
data_source
);
char
*
port
=
pcre_match
(
"(port=([^;
\\
s]+))"
,
sizeof
(
"(port=([^;
\\
s]+))"
)
-
1
,
(
char
*
)
stmt
->
dbh
->
data_source
);
if
(
host
!=
NULL
&&
port
!=
NULL
)
{
peer
=
(
char
*
)
emalloc
(
strlen
(
host
)
+
10
);
bzero
(
peer
,
strlen
(
host
)
+
10
);
sprintf
(
peer
,
"%s:%s"
,
host
,
port
);
}
if
(
host
!=
NULL
)
efree
(
host
);
if
(
port
!=
NULL
)
efree
(
port
);
}
}
}
else
if
(
strcmp
(
class_name
,
"mysqli"
)
==
0
)
{
...
...
@@ -354,11 +403,16 @@ ZEND_API void sky_execute_internal(zend_execute_data *execute_data, zval *return
if
(
my_res
&&
my_res
->
ptr
)
{
MY_MYSQL
*
mysql
=
(
MY_MYSQL
*
)
my_res
->
ptr
;
if
(
mysql
->
mysql
)
{
add_assoc_string
(
&
tags
,
"db.host"
,
mysql
->
mysql
->
data
->
host
);
#if PHP_VERSION_ID >= 70200
char
*
host
=
mysql
->
mysql
->
data
->
hostname
.
s
;
#else
char
*
host
=
mysql
->
mysql
->
data
->
host
;
#endif
add_assoc_string
(
&
tags
,
"db.host"
,
host
);
add_assoc_long
(
&
tags
,
"db.port"
,
mysql
->
mysql
->
data
->
port
);
peer
=
(
char
*
)
emalloc
(
strlen
(
mysql
->
mysql
->
data
->
host
)
+
10
);
bzero
(
peer
,
strlen
(
mysql
->
mysql
->
data
->
host
)
+
10
);
sprintf
(
peer
,
"%s:%d"
,
mysql
->
mysql
->
data
->
host
,
mysql
->
mysql
->
data
->
port
);
peer
=
(
char
*
)
emalloc
(
strlen
(
host
)
+
10
);
bzero
(
peer
,
strlen
(
host
)
+
10
);
sprintf
(
peer
,
"%s:%d"
,
host
,
mysql
->
mysql
->
data
->
port
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录