Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
SkyAPM
SkyAPM-php-sdk
提交
80f3352b
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,发现更多精彩内容 >>
提交
80f3352b
编写于
12月 12, 2018
作者:
H
heyanlong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
memory
上级
ca664a36
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
58 addition
and
30 deletion
+58
-30
sky-php7ext/skywalking.c
sky-php7ext/skywalking.c
+58
-30
未找到文件。
sky-php7ext/skywalking.c
浏览文件 @
80f3352b
...
@@ -143,7 +143,11 @@ void sky_curl_exec_handler(INTERNAL_FUNCTION_PARAMETERS)
...
@@ -143,7 +143,11 @@ void sky_curl_exec_handler(INTERNAL_FUNCTION_PARAMETERS)
ZVAL_COPY
(
&
params
[
0
],
zid
);
ZVAL_COPY
(
&
params
[
0
],
zid
);
ZVAL_STRING
(
&
function_name
,
"curl_getinfo"
);
ZVAL_STRING
(
&
function_name
,
"curl_getinfo"
);
call_user_function
(
CG
(
function_table
),
NULL
,
&
function_name
,
&
curlInfo
,
1
,
params
);
call_user_function
(
CG
(
function_table
),
NULL
,
&
function_name
,
&
curlInfo
,
1
,
params
);
zval_dtor
(
&
function_name
);
zval_dtor
(
&
params
[
0
]);
zval
*
z_url
=
zend_hash_str_find
(
Z_ARRVAL
(
curlInfo
),
ZEND_STRL
(
"url"
));
zval
*
z_url
=
zend_hash_str_find
(
Z_ARRVAL
(
curlInfo
),
ZEND_STRL
(
"url"
));
zval_dtor
(
&
curlInfo
);
php_url
*
url_info
=
php_url_parse
(
Z_STRVAL_P
(
z_url
)
);
php_url
*
url_info
=
php_url_parse
(
Z_STRVAL_P
(
z_url
)
);
char
peer
[
200
];
char
peer
[
200
];
...
@@ -165,7 +169,13 @@ void sky_curl_exec_handler(INTERNAL_FUNCTION_PARAMETERS)
...
@@ -165,7 +169,13 @@ void sky_curl_exec_handler(INTERNAL_FUNCTION_PARAMETERS)
sprintf
(
operation_name
,
"%s"
,
url_info
->
path
);
sprintf
(
operation_name
,
"%s"
,
url_info
->
path
);
}
}
char
*
sw3
=
generate_sw3
(
Z_LVAL_P
(
span_id
)
+
1
,
zend_string_init
(
peer
,
sizeof
(
peer
)
-
1
,
1
),
zend_string_init
(
operation_name
,
sizeof
(
operation_name
)
-
1
,
1
));
zend_string
*
_peer_host
,
*
_op_name
;
_peer_host
=
zend_string_init
(
peer
,
sizeof
(
peer
)
-
1
,
0
);
_op_name
=
zend_string_init
(
operation_name
,
sizeof
(
operation_name
)
-
1
,
0
);
char
*
sw3
=
generate_sw3
(
Z_LVAL_P
(
span_id
)
+
1
,
_peer_host
,
_op_name
);
zend_string_release
(
_peer_host
);
zend_string_release
(
_op_name
);
if
(
sw3
!=
NULL
)
{
if
(
sw3
!=
NULL
)
{
zval
z_sw3
;
zval
z_sw3
;
...
@@ -178,11 +188,15 @@ void sky_curl_exec_handler(INTERNAL_FUNCTION_PARAMETERS)
...
@@ -178,11 +188,15 @@ void sky_curl_exec_handler(INTERNAL_FUNCTION_PARAMETERS)
ZVAL_COPY
(
&
p
[
0
],
zid
);
ZVAL_COPY
(
&
p
[
0
],
zid
);
ZVAL_LONG
(
&
p
[
1
],
CURLOPT_HTTPHEADER
);
ZVAL_LONG
(
&
p
[
1
],
CURLOPT_HTTPHEADER
);
ZVAL_COPY
(
&
p
[
2
],
&
z_sw3
);
ZVAL_COPY
(
&
p
[
2
],
&
z_sw3
);
zval_dtor
(
&
z_sw3
);
ZVAL_STRING
(
&
f_name
,
"curl_setopt"
);
ZVAL_STRING
(
&
f_name
,
"curl_setopt"
);
zval
return_function_value
;
zval
return_function_value
;
call_user_function
(
CG
(
function_table
),
NULL
,
&
f_name
,
&
return_function_value
,
3
,
p
);
call_user_function
(
CG
(
function_table
),
NULL
,
&
f_name
,
&
return_function_value
,
3
,
p
);
zval_ptr_dtor
(
&
p
[
0
]);
zval_dtor
(
&
return_function_value
);
zval_ptr_dtor
(
&
p
[
2
]);
zval_dtor
(
&
f_name
);
zval_dtor
(
&
p
[
0
]);
zval_dtor
(
&
p
[
1
]);
zval_dtor
(
&
p
[
2
]);
}
}
efree
(
sw3
);
efree
(
sw3
);
...
@@ -191,8 +205,8 @@ void sky_curl_exec_handler(INTERNAL_FUNCTION_PARAMETERS)
...
@@ -191,8 +205,8 @@ void sky_curl_exec_handler(INTERNAL_FUNCTION_PARAMETERS)
call_user_function
(
CG
(
function_table
),
NULL
,
&
function_name
,
&
curlInfo
,
1
,
params
);
call_user_function
(
CG
(
function_table
),
NULL
,
&
function_name
,
&
curlInfo
,
1
,
params
);
zval_
ptr_
dtor
(
&
params
[
0
]);
zval_dtor
(
&
params
[
0
]);
zval_dtor
(
&
function_name
);
zval
*
z_http_code
;
zval
*
z_http_code
;
l_millisecond
=
get_millisecond
();
l_millisecond
=
get_millisecond
();
...
@@ -200,6 +214,7 @@ void sky_curl_exec_handler(INTERNAL_FUNCTION_PARAMETERS)
...
@@ -200,6 +214,7 @@ void sky_curl_exec_handler(INTERNAL_FUNCTION_PARAMETERS)
efree
(
l_millisecond
);
efree
(
l_millisecond
);
z_http_code
=
zend_hash_str_find
(
Z_ARRVAL
(
curlInfo
),
ZEND_STRL
(
"http_code"
));
z_http_code
=
zend_hash_str_find
(
Z_ARRVAL
(
curlInfo
),
ZEND_STRL
(
"http_code"
));
zval_dtor
(
&
curlInfo
);
add_assoc_long
(
&
temp
,
"endTime"
,
millisecond
);
add_assoc_long
(
&
temp
,
"endTime"
,
millisecond
);
...
@@ -246,25 +261,32 @@ static char *sky_json_encode(zval *parameter){
...
@@ -246,25 +261,32 @@ static char *sky_json_encode(zval *parameter){
php_json_encode
(
&
buf
,
parameter
,
(
int
)
options
);
php_json_encode
(
&
buf
,
parameter
,
(
int
)
options
);
#endif
#endif
smart_str_0
(
&
buf
);
smart_str_0
(
&
buf
);
return
ZSTR_VAL
(
buf
.
s
);
char
*
bufs
=
ZSTR_VAL
(
buf
.
s
);
smart_str_free
(
&
buf
);
return
bufs
;
}
}
static
void
write_log
(
char
*
text
){
static
void
write_log
(
char
*
text
)
{
if
(
application_instance
!=
-
100000
)
{
if
(
application_instance
!=
-
100000
)
{
char
*
log_path
;
char
*
log_path
;
char
logFilename
[
100
];
char
logFilename
[
100
];
char
message
[
strlen
(
text
)
+
1
];
char
message
[
strlen
(
text
)
+
1
];
log_path
=
SKY_G
(
log_path
);
log_path
=
SKY_G
(
log_path
);
zend_string
*
date_fmt
;
zend_string
*
date_fmt
,
*
_log_path
,
*
_log_path_lower
;
time_t
t
;
time_t
t
;
t
=
time
(
NULL
);
t
=
time
(
NULL
);
date_fmt
=
php_format_date
(
"YmdHi"
,
sizeof
(
"YmdHi"
)
-
1
,
t
,
1
);
date_fmt
=
php_format_date
(
"YmdHi"
,
sizeof
(
"YmdHi"
)
-
1
,
t
,
1
);
_log_path
=
zend_string_init
(
log_path
,
strlen
(
log_path
),
0
);
_log_path_lower
=
php_string_tolower
(
_log_path
);
bzero
(
logFilename
,
100
);
bzero
(
logFilename
,
100
);
sprintf
(
logFilename
,
"%s/skywalking.%s.log"
,
ZSTR_VAL
(
php_string_tolower
(
zend_string_init
(
log_path
,
strlen
(
log_path
),
0
))
),
ZSTR_VAL
(
date_fmt
));
sprintf
(
logFilename
,
"%s/skywalking.%s.log"
,
ZSTR_VAL
(
_log_path_lower
),
ZSTR_VAL
(
date_fmt
));
zend_string_release
(
date_fmt
);
zend_string_release
(
_log_path
);
zend_string_release
(
_log_path_lower
);
bzero
(
message
,
strlen
(
text
));
bzero
(
message
,
strlen
(
text
));
sprintf
(
message
,
"%s
\n
"
,
text
);
sprintf
(
message
,
"%s
\n
"
,
text
);
_php_error_log_ex
(
3
,
message
,
strlen
(
message
),
logFilename
,
NULL
);
_php_error_log_ex
(
3
,
message
,
strlen
(
message
),
logFilename
,
NULL
);
...
@@ -306,7 +328,6 @@ static void generate_context() {
...
@@ -306,7 +328,6 @@ static void generate_context() {
sprintf
(
makeTraceId
,
"%d.%d.%ld"
,
application_instance
,
sys_pid
,
second
);
sprintf
(
makeTraceId
,
"%d.%d.%ld"
,
application_instance
,
sys_pid
,
second
);
add_assoc_string
(
&
SKYWALKING_G
(
context
),
"currentTraceId"
,
makeTraceId
);
add_assoc_string
(
&
SKYWALKING_G
(
context
),
"currentTraceId"
,
makeTraceId
);
// efree(makeTraceId);
add_assoc_long
(
&
SKYWALKING_G
(
context
),
"isChild"
,
0
);
add_assoc_long
(
&
SKYWALKING_G
(
context
),
"isChild"
,
0
);
// parent
// parent
...
@@ -357,6 +378,7 @@ static void generate_context() {
...
@@ -357,6 +378,7 @@ static void generate_context() {
add_assoc_string
(
&
SKYWALKING_G
(
context
),
"entryOperationName"
,
get_page_request_uri
());
add_assoc_string
(
&
SKYWALKING_G
(
context
),
"entryOperationName"
,
get_page_request_uri
());
add_assoc_string
(
&
SKYWALKING_G
(
context
),
"distributedTraceId"
,
makeTraceId
);
add_assoc_string
(
&
SKYWALKING_G
(
context
),
"distributedTraceId"
,
makeTraceId
);
}
}
efree
(
makeTraceId
);
}
}
...
@@ -403,7 +425,9 @@ static char *get_page_request_uri() {
...
@@ -403,7 +425,9 @@ static char *get_page_request_uri() {
}
}
smart_str_0
(
&
uri
);
smart_str_0
(
&
uri
);
return
ZSTR_VAL
(
uri
.
s
);
char
*
uris
=
ZSTR_VAL
(
uri
.
s
);
smart_str_free
(
&
uri
);
return
uris
;
}
}
...
@@ -479,10 +503,10 @@ static void request_init() {
...
@@ -479,10 +503,10 @@ static void request_init() {
zval
*
isChild
=
zend_hash_str_find
(
Z_ARRVAL_P
(
&
SKYWALKING_G
(
context
)),
"isChild"
,
sizeof
(
"isChild"
)
-
1
);
zval
*
isChild
=
zend_hash_str_find
(
Z_ARRVAL_P
(
&
SKYWALKING_G
(
context
)),
"isChild"
,
sizeof
(
"isChild"
)
-
1
);
// refs
// refs
zval
refs
;
zval
refs
;
zval
ref
;
array_init
(
&
refs
);
array_init
(
&
refs
);
array_init
(
&
ref
);
if
(
Z_LVAL_P
(
isChild
)
==
1
)
{
if
(
Z_LVAL_P
(
isChild
)
==
1
)
{
zval
ref
;
array_init
(
&
ref
);
zval
*
parentTraceSegmentId
=
zend_hash_str_find
(
Z_ARRVAL
(
SKYWALKING_G
(
context
)),
"parentTraceSegmentId"
,
sizeof
(
"parentTraceSegmentId"
)
-
1
);
zval
*
parentTraceSegmentId
=
zend_hash_str_find
(
Z_ARRVAL
(
SKYWALKING_G
(
context
)),
"parentTraceSegmentId"
,
sizeof
(
"parentTraceSegmentId"
)
-
1
);
zval
*
parentSpanId
=
zend_hash_str_find
(
Z_ARRVAL
(
SKYWALKING_G
(
context
)),
"parentSpanId"
,
sizeof
(
"parentSpanId"
)
-
1
);
zval
*
parentSpanId
=
zend_hash_str_find
(
Z_ARRVAL
(
SKYWALKING_G
(
context
)),
"parentSpanId"
,
sizeof
(
"parentSpanId"
)
-
1
);
zval
*
parentApplicationInstance
=
zend_hash_str_find
(
Z_ARRVAL
(
SKYWALKING_G
(
context
)),
"parentApplicationInstance"
,
sizeof
(
"parentApplicationInstance"
)
-
1
);
zval
*
parentApplicationInstance
=
zend_hash_str_find
(
Z_ARRVAL
(
SKYWALKING_G
(
context
)),
"parentApplicationInstance"
,
sizeof
(
"parentApplicationInstance"
)
-
1
);
...
@@ -510,7 +534,6 @@ static void request_init() {
...
@@ -510,7 +534,6 @@ static void request_init() {
zval
globalTraceIds
;
zval
globalTraceIds
;
array_init
(
&
globalTraceIds
);
array_init
(
&
globalTraceIds
);
zval
tmpGlobalTraceIds
;
zval
tmpGlobalTraceIds
;
array_init
(
&
tmpGlobalTraceIds
);
ZVAL_STRING
(
&
tmpGlobalTraceIds
,
Z_STRVAL_P
(
traceId
));
ZVAL_STRING
(
&
tmpGlobalTraceIds
,
Z_STRVAL_P
(
traceId
));
zend_hash_next_index_insert
(
Z_ARRVAL
(
globalTraceIds
),
&
tmpGlobalTraceIds
);
zend_hash_next_index_insert
(
Z_ARRVAL
(
globalTraceIds
),
&
tmpGlobalTraceIds
);
...
@@ -599,7 +622,6 @@ static void module_init() {
...
@@ -599,7 +622,6 @@ static void module_init() {
i
++
;
i
++
;
}
while
(
application_instance
==
-
100000
&&
i
<=
3
);
}
while
(
application_instance
==
-
100000
&&
i
<=
3
);
// efree(ipv4s);
if
(
application_instance
==
-
100000
)
{
if
(
application_instance
==
-
100000
)
{
sky_close
=
1
;
sky_close
=
1
;
...
@@ -611,10 +633,9 @@ static void module_init() {
...
@@ -611,10 +633,9 @@ static void module_init() {
/* {{{ PHP_MINIT_FUNCTION
/* {{{ PHP_MINIT_FUNCTION
*/
*/
PHP_MINIT_FUNCTION
(
skywalking
)
{
PHP_MINIT_FUNCTION
(
skywalking
)
{
ZEND_INIT_MODULE_GLOBALS
(
skywalking
,
php_skywalking_init_globals
,
NULL
);
//
ZEND_INIT_MODULE_GLOBALS(skywalking, php_skywalking_init_globals, NULL);
//data_register_hashtable();
//data_register_hashtable();
REGISTER_INI_ENTRIES
();
REGISTER_INI_ENTRIES
();
/* If you have INI entries, uncomment these lines
/* If you have INI entries, uncomment these lines
*/
*/
if
(
SKYWALKING_G
(
enable
))
{
if
(
SKYWALKING_G
(
enable
))
{
...
@@ -639,15 +660,7 @@ PHP_MINIT_FUNCTION (skywalking) {
...
@@ -639,15 +660,7 @@ PHP_MINIT_FUNCTION (skywalking) {
PHP_MSHUTDOWN_FUNCTION
(
skywalking
)
PHP_MSHUTDOWN_FUNCTION
(
skywalking
)
{
{
UNREGISTER_INI_ENTRIES
();
UNREGISTER_INI_ENTRIES
();
if
(
SKYWALKING_G
(
enable
))
{
return
SUCCESS
;
if
(
sky_close
==
1
)
{
return
SUCCESS
;
}
// zval_dtor(&SKYWALKING_G(context));
// zval_dtor(&SKYWALKING_G(UpstreamSegment));
}
return
SUCCESS
;
}
}
/* }}} */
/* }}} */
...
@@ -668,9 +681,8 @@ PHP_RINIT_FUNCTION(skywalking)
...
@@ -668,9 +681,8 @@ PHP_RINIT_FUNCTION(skywalking)
if
(
sky_increment_id
>=
9999
)
{
if
(
sky_increment_id
>=
9999
)
{
sky_increment_id
=
0
;
sky_increment_id
=
0
;
}
}
request_init
();
request_init
();
}
}
return
SUCCESS
;
return
SUCCESS
;
}
}
/* }}} */
/* }}} */
...
@@ -682,9 +694,13 @@ PHP_RSHUTDOWN_FUNCTION(skywalking)
...
@@ -682,9 +694,13 @@ PHP_RSHUTDOWN_FUNCTION(skywalking)
{
{
if
(
SKYWALKING_G
(
enable
)){
if
(
SKYWALKING_G
(
enable
)){
if
(
sky_close
==
1
)
{
return
SUCCESS
;
}
sky_flush_all
();
sky_flush_all
();
zval_dtor
(
&
SKYWALKING_G
(
context
));
zval_dtor
(
&
SKYWALKING_G
(
UpstreamSegment
));
}
}
return
SUCCESS
;
return
SUCCESS
;
}
}
/* }}} */
/* }}} */
...
@@ -704,6 +720,18 @@ PHP_MINFO_FUNCTION(skywalking)
...
@@ -704,6 +720,18 @@ PHP_MINFO_FUNCTION(skywalking)
}
}
/* }}} */
/* }}} */
/* {{{ PHP_MINFO_FUNCTION
*/
PHP_GINIT_FUNCTION
(
skywalking
)
{
memset
(
skywalking_globals
,
0
,
sizeof
(
*
skywalking_globals
));
}
/* }}} */
zend_module_dep
skywalking_deps
[]
=
{
ZEND_MOD_REQUIRED
(
"json"
)
{
NULL
,
NULL
,
NULL
}
};
/* {{{ skywalking_module_entry
/* {{{ skywalking_module_entry
*/
*/
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录