Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
SkyAPM
SkyAPM-php-sdk
提交
4d708952
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,发现更多精彩内容 >>
提交
4d708952
编写于
6月 24, 2019
作者:
H
heyanlong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
send trace to stream
上级
0a0ce842
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
67 addition
and
31 deletion
+67
-31
skywalking.c
skywalking.c
+67
-31
未找到文件。
skywalking.c
浏览文件 @
4d708952
...
...
@@ -65,6 +65,7 @@ static int application_instance = -100000;
static
int
application_id
=
-
100000
;
static
int
sky_close
=
0
;
static
int
sky_increment_id
=
0
;
static
int
cli_debug
=
1
;
const
char
*
sock_path
=
"/tmp/sky_agent.sock"
;
/* {{{ PHP_INI
...
...
@@ -419,23 +420,48 @@ static char *sky_json_encode(zval *parameter){
static
void
write_log
(
char
*
text
)
{
if
(
application_instance
!=
-
100000
)
{
char
*
log_path
;
char
logFilename
[
100
];
char
message
[
strlen
(
text
)
+
1
];
log_path
=
SKY_G
(
log_path
);
zend_string
*
_log_path
,
*
_log_path_lower
;
_log_path
=
zend_string_init
(
log_path
,
strlen
(
log_path
),
0
);
_log_path_lower
=
php_string_tolower
(
_log_path
);
bzero
(
logFilename
,
100
);
sprintf
(
logFilename
,
"%s/skywalking.%d-%d.log"
,
ZSTR_VAL
(
_log_path_lower
),
get_second
(),
getpid
());
zend_string_release
(
_log_path
);
zend_string_release
(
_log_path_lower
);
bzero
(
message
,
strlen
(
text
));
sprintf
(
message
,
"%s
\n
"
,
text
);
_php_error_log_ex
(
3
,
message
,
strlen
(
message
),
logFilename
,
NULL
);
// to file
// char *log_path;
// char logFilename[100];
// char message[strlen(text) + 1];
// log_path = SKY_G(log_path);
//
// zend_string *_log_path, *_log_path_lower;
// _log_path = zend_string_init(log_path, strlen(log_path), 0);
// _log_path_lower = php_string_tolower(_log_path);
//
// bzero(logFilename, 100);
// sprintf(logFilename, "%s/skywalking.%d-%d.log", ZSTR_VAL(_log_path_lower), get_second(), getpid());
//
// zend_string_release(_log_path);
// zend_string_release(_log_path_lower);
// bzero(message, strlen(text));
// sprintf(message, "%s\n", text);
// _php_error_log_ex(3, message, strlen(message), logFilename, NULL);
// to stream
struct
sockaddr_un
un
;
un
.
sun_family
=
AF_UNIX
;
strcpy
(
un
.
sun_path
,
sock_path
);
int
fd
;
char
message
[
strlen
(
text
)
+
2
];
fd
=
socket
(
AF_UNIX
,
SOCK_STREAM
,
0
);
if
(
fd
>=
0
)
{
struct
timeval
tv
;
tv
.
tv_sec
=
0
;
tv
.
tv_usec
=
100000
;
setsockopt
(
fd
,
SOL_SOCKET
,
SO_RCVTIMEO
,
(
const
char
*
)
&
tv
,
sizeof
tv
);
int
conn
=
connect
(
fd
,
(
struct
sockaddr
*
)
&
un
,
sizeof
(
un
));
if
(
conn
>=
0
)
{
bzero
(
message
,
strlen
(
text
)
+
2
);
sprintf
(
message
,
"1%s
\n
"
,
text
);
write
(
fd
,
message
,
strlen
(
message
));
}
close
(
fd
);
}
}
}
...
...
@@ -879,6 +905,10 @@ static int sky_register() {
fd
=
socket
(
AF_UNIX
,
SOCK_STREAM
,
0
);
if
(
fd
>=
0
)
{
struct
timeval
tv
;
tv
.
tv_sec
=
0
;
tv
.
tv_usec
=
100000
;
setsockopt
(
fd
,
SOL_SOCKET
,
SO_RCVTIMEO
,
(
const
char
*
)
&
tv
,
sizeof
tv
);
int
conn
=
connect
(
fd
,
(
struct
sockaddr
*
)
&
un
,
sizeof
(
un
));
if
(
conn
>=
0
)
{
...
...
@@ -889,18 +919,16 @@ static int sky_register() {
bzero
(
return_message
,
sizeof
(
return_message
));
read
(
fd
,
return_message
,
sizeof
(
return_message
));
application_id
=
atoi
(
return_message
);
if
(
application_id
!=
-
100000
)
{
bzero
(
message
,
sizeof
(
message
));
sprintf
(
message
,
"1{
\"
application_id
\"
:
\"
%d
\"
,
\"
pid
\"
:%d}
\n
"
,
application_id
,
getppid
());
write
(
fd
,
message
,
strlen
(
message
));
bzero
(
return_message
,
sizeof
(
return_message
));
read
(
fd
,
return_message
,
sizeof
(
return_message
));
application_instance
=
atoi
(
return_message
);
char
*
ids
[
10
];
int
i
=
0
;
char
*
p
=
strtok
(
return_message
,
","
);
while
(
p
!=
NULL
)
{
ids
[
i
++
]
=
p
;
p
=
strtok
(
NULL
,
"/"
);
}
application_id
=
atoi
(
ids
[
0
]);
application_instance
=
atoi
(
ids
[
1
]);
}
close
(
fd
);
...
...
@@ -919,7 +947,7 @@ PHP_MINIT_FUNCTION (skywalking) {
/* If you have INI entries, uncomment these lines
*/
if
(
SKYWALKING_G
(
enable
))
{
if
(
strcasecmp
(
"cli"
,
sapi_module
.
name
)
==
0
)
{
if
(
strcasecmp
(
"cli"
,
sapi_module
.
name
)
==
0
&&
cli_debug
==
0
)
{
return
SUCCESS
;
}
...
...
@@ -966,10 +994,15 @@ PHP_RINIT_FUNCTION(skywalking)
ZEND_TSRMLS_CACHE_UPDATE
();
#endif
if
(
SKYWALKING_G
(
enable
))
{
if
(
strcasecmp
(
"cli"
,
sapi_module
.
name
)
==
0
&&
cli_debug
==
0
)
{
return
SUCCESS
;
}
sky_register
();
if
(
application_id
==
-
100000
||
application_instance
==
-
100000
)
{
if
(
application_id
==
-
100000
||
application_instance
==
-
100000
)
{
sky_close
=
1
;
return
SUCCESS
;
}
else
{
sky_close
=
0
;
}
sky_increment_id
++
;
if
(
sky_increment_id
>=
9999
)
{
...
...
@@ -988,6 +1021,9 @@ PHP_RSHUTDOWN_FUNCTION(skywalking)
{
if
(
SKYWALKING_G
(
enable
)){
if
(
strcasecmp
(
"cli"
,
sapi_module
.
name
)
==
0
&&
cli_debug
==
0
)
{
return
SUCCESS
;
}
if
(
sky_close
==
1
)
{
return
SUCCESS
;
}
...
...
@@ -1013,7 +1049,7 @@ PHP_MINFO_FUNCTION(skywalking)
php_info_print_table_header
(
2
,
"SkyWalking Support"
,
"disabled"
);
}
php_info_print_table_header
(
2
,
"SkyWalking Agent"
,
"/tmp/
agent_repor
t.sock"
);
php_info_print_table_header
(
2
,
"SkyWalking Agent"
,
"/tmp/
sky_agen
t.sock"
);
php_info_print_table_end
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录