未验证 提交 76e9406a 编写于 作者: S songzhian 提交者: GitHub

Merge pull request #11 from SkywalkingContrib/songzhian

Songzhian
Sky Walking for php SDK| [中文](README_ZH.md)
==========
**SkyWalking php SDK**: A client tool developed for PHP using SkyWalking APM tools. (It is a pity that it only supports writing log and checking curl currently.)
SkyWalking APM : https://github.com/OpenSkywalking/skywalking
SkyWalking APM : https://github.com/apache/incubator-skywalking
* Automatic probe for PHP. **You don't need to modify the application code.**
* It is a PHP extension developed by zendAPI.
......@@ -20,7 +20,7 @@ SkyWalking APM : https://github.com/OpenSkywalking/skywalking
# Apply to
* version 1.0 applies to Skywalking 3.1 .
* version 2.0 applies to Skywalking 3.X .
# In the future.
* more php versions.
* more os.
......
......@@ -3,7 +3,7 @@ Sky Walking SDK for PHP | [English](README.md)
**SkyWalking php SDK**: 针对SkyWalking APM工具为php开发的客户端工具 (目前只支持写日志方式和只针对curl检测)
SkyWalking APM : https://github.com/OpenSkywalking/skywalking
SkyWalking APM : https://github.com/apache/incubator-skywalking
* PHP 自动探针 **不需要修改应用程序代码**
* 使用zendAPI开发的 php扩展
......@@ -17,12 +17,12 @@ SkyWalking APM : https://github.com/OpenSkywalking/skywalking
# 使用安装
* php扩展包(https://github.com/SkywalkingContrib/skywalking-php-sdk/tree/songzhian/sky-php7ext)
* php代码类包(https://github.com/SkywalkingContrib/skywalking-php-sdk/tree/songzhian/sdk-php)
* php扩展包(https://github.com/SkywalkingContrib/skywalking-php-sdk/blob/songzhian/sky-php7ext/README_ZH.md)
* php代码类包(https://github.com/SkywalkingContrib/skywalking-php-sdk/blob/songzhian/sdk-php/README_ZH.md)
# 对应版本支持
* 1.0对应版本:Skywalking 3.1
* 2.0对应版本:Skywalking 3.x
# 将要完成
* 其它php版本扩展支持
* 更多系统支持
......
# PHP SkyWalking 类: SkyWalking PHP 客户端
---
- [安装](#installation)
- [要求](#requirements)
- [快速开始实例](#quick-start-and-examples)
---
### Installation
使用安装 SkyWalking 类, 操作:
### Requirements
PHP Curl Class works with PHP 5.2 - 7.9.99 , and HHVM.
### Quick Start and Examples
// must put these code at the beginning !!!
// that would auto register shutdown function !!!
include_once ("./sdk-php/SkyWalking.php");// or use composer
//LOG_PATH is skywalking's logfile path
SkyWalking::getInstance("api")->setLogPath(LOG_PATH)->setSamplingRate(5);
....
....
$ch = curl_init();
curl_setopt($ch);
....
....
SkyWalking::getInstance()->startSpanOfCurl("www.api.com", $headers);
....
....
curl_setopt($ch);
$rs = curl_exec($ch);
SkyWalking::getInstance()->endSpanOfcurl($ch);
....
....
\ No newline at end of file
此差异已折叠。
......@@ -24,31 +24,9 @@ copy ini to php.ini
the current phpext works with PHP 7.0-7.9.99 。
this extension references something external, use with: pphcurl、phpjson and phpstandard
need to install, Please refer to: https://github.com/grpc/grpc/blob/master/INSTALL.md
### Documentation
- https://github.com/OpenSkywalking/skywalking/wiki
### Quick Start and Examples
set php.ini skywalking.auto_open = On (Automatic writing **Ignore the following**)
OR skywalking.auto_open = OFF (the project int code )As below:
// must put these code at the beginning !!!
....
....
$ch = curl_init();
curl_setopt($ch);
SkyWalking::getInstance()->startSpanOfCurl("www.api.com", $headers);
....
....
curl_setopt($ch);
$rs = curl_exec($ch);
SkyWalking::getInstance()->endSpanOfcurl($ch);
....
....
set php.ini skywalking.auto_open = On (Automatic writing **Ignore the following**)
\ No newline at end of file
# PHP SkyWalking Class: SkyWalking PHP client
---
- [安装](#installation)
- [要求](#requirements)
- [Quick Start and Examples](#quick-start-and-examples)
---
### Installation
快速安装
复制ini内容到php.ini
git clone https://github.com/SkywalkingContrib/skywalking-php-sdk.git
cd skywalking-php-sdk/sky-php7ext
phpize
./configure
make -j [number_of_processor_cores] # eg. make -j 4
make install
### Requirements
扩展支持版本 7.0-7.9.99 。
这个扩展需要其他扩展支持: pphcurl、phpjson和phpstandard 包
需要安装GRPC 请参照 : https://github.com/grpc/grpc/blob/master/INSTALL.md
### 快速启动
设置 php.ini skywalking.auto_open = On (自动开启信息抓取 **Ignore the following**)
......@@ -62,6 +62,43 @@ if test "$PHP_SKYWALKING" != "no"; then
dnl ])
dnl
dnl PHP_SUBST(SKYWALKING_SHARED_LIBADD)
PHP_REQUIRE_CXX()
PHP_NEW_EXTENSION(skywalking, skywalking.c, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
KYWALKING_LIBS=" -L/usr/local/lib "
KYWALKING_LIBS+=`pkg-config --libs protobuf grpc++ grpc`
KYWALKING_LIBS+="-Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed -ldl"
AC_OUTPUT_COMMANDS(
protoc -I ./protos --cpp_out=./grpc ./protos/DiscoveryService.proto
protoc -I ./protos --cpp_out=./grpc ./protos/ApplicationRegisterService.proto
protoc -I ./protos --cpp_out=./grpc ./protos/TraceSegmentService.proto
)
AC_OUTPUT_COMMANDS(
protoc -I ./protos --grpc_out=./grpc --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` ./protos/DiscoveryService.proto
protoc -I ./protos --grpc_out=./grpc --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` ./protos/ApplicationRegisterService.proto
protoc -I ./protos --grpc_out=./grpc --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` ./protos/TraceSegmentService.proto
)
AC_OUTPUT_COMMANDS(
mv grpc/DiscoveryService.grpc.pb.cc grpc/DiscoveryService-grpc.pb.cc
mv grpc/ApplicationRegisterService.grpc.pb.cc grpc/ApplicationRegisterService-grpc.pb.cc
mv grpc/TraceSegmentService.grpc.pb.cc grpc/TraceSegmentService-grpc.pb.cc
)
PHP_EVAL_LIBLINE($KYWALKING_LIBS, SKYWALKING_SHARED_LIBADD)
PHP_NEW_EXTENSION(skywalking, \
skywalking.c \
grpc/greeter_client.cc \
grpc/DiscoveryService.pb.cc \
grpc/DiscoveryService-grpc.pb.cc \
grpc/ApplicationRegisterService.pb.cc \
grpc/ApplicationRegisterService-grpc.pb.cc \
grpc/TraceSegmentService.pb.cc \
grpc/TraceSegmentService-grpc.pb.cc \
, $ext_shared,, -std=c++11 -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
PHP_ADD_BUILD_DIR($ext_builddir/grpc)
PHP_SUBST(SKYWALKING_SHARED_LIBADD)
fi
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: DiscoveryService.proto
#ifndef DISCOVERY_CLIENT_C_H
#define DISCOVERY_CLIENT_C_H
#define METHOD__GO_REGISTER 1
#define METHOD__GO_REGISTER_INSTANCE 2
#define METHOD__SEND_TRACE_SEGMENT 3
typedef struct _RegisterParamtruct
{
char* appCode;
}RegisterParamtruct;
typedef struct _RegisterInstanceParamtruct
{
char* agentUUID;
char* osName;;
char* hostname;
char* ipv4s;
int applicationId;
long registerTime;
int processNo;
}RegisterInstanceParamtruct;
typedef enum _SpanTypeStruct
{
Entry_x,
Exit_x,
Local_x
}SpanTypeStruct;
typedef enum _SpanLayerStruct
{
Unknown_x,
Database_x,
RPCFramework_x,
Http_x,
MQ_x,
Cache_x
}SpanLayerStruct;
typedef struct _KeyWithStringValueStruct
{
int key;
char *value;
}KeyWithStringValueStruct;
typedef struct _LogMessageStruct
{
long time;
KeyWithStringValueStruct* data;
}LogMessageStruct;
typedef enum _RefTypeStruct
{
CrossProcess_x,
CrossThread_x
}RefTypeStruct;
typedef struct _UniqueIdStruct
{
long idParts;
}UniqueIdStruct;
typedef struct _TraceSegmentReferenceStruct
{
RefTypeStruct* refType;
UniqueIdStruct* parentTraceSegmentId;
int parentSpanId;
int parentApplicationInstanceId;
int networkAddress;
int networkAddressId;
int entryApplicationInstanceId;
char* entryServiceName;
int entryServiceId;
char* parentServiceName;
int* parentServiceId;
}TraceSegmentReferenceStruct;
typedef struct _SpanObjectStruct
{
int spanId;
int parentSpanId;
long startTime;
long endTime;
TraceSegmentReferenceStruct* refs;
int operationNameId;
char *operationName;
int peerId;
char *peer;
SpanTypeStruct* spanType;
SpanLayerStruct* spanLayer;
int componentId;
int isError;
KeyWithStringValueStruct* tags;
LogMessageStruct* logs;
}SpanObjectStruct;
typedef struct _comListNode
{
UniqueIdStruct* data;
struct _comListNode* next;
} comListNode;
typedef struct _comList
{
struct _comListNode* head;
struct _comListNode* tail;
int count;
} comList;
typedef struct _TraceSegmentObjectStruct
{
comList* traceSegmentIdList;
SpanObjectStruct *spans;
char *segment;
int applicationId;
int applicationInstanceId;
int isSizeLimited;
}TraceSegmentObjectStruct;
typedef struct _SendTraceSegmentParamStruct
{
TraceSegmentObjectStruct* traceSegment;
}SendTraceSegmentParamStruct;
typedef union _ParamDataStruct
{
RegisterParamtruct* registerParam;
RegisterInstanceParamtruct* registerInstanceParam;
SendTraceSegmentParamStruct* sendTraceSegmentParam;
} ParamDataStruct;
typedef struct _UpstreamSegmentStruct
{
UniqueIdStruct* globalTraceIds;
char *segment;
}UpstreamSegmentStruct;
typedef struct AppInstanceStruct
{
int applicationId;
int applicationInstanceId;
} AppInstance;
#endif /* #ifndef DISCOVERY_CLIENT_C_H */
\ No newline at end of file
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include <iostream>
#include <memory>
#include <string>
#include <grpc++/grpc++.h>
#include "ApplicationRegisterService.grpc.pb.h"
#include "DiscoveryService.grpc.pb.h"
#include "TraceSegmentService.grpc.pb.h"
#include "common_struct.h"
using grpc::Channel;
using grpc::ClientContext;
using grpc::Status;
using grpc::ClientReader;
using grpc::ClientReaderWriter;
using grpc::ClientWriter;
extern "C" int goSkyGrpc(char*host, int method, ParamDataStruct* paramData, void (*callfuct)( AppInstance* ) );
class GreeterClient {
public:
GreeterClient(std::shared_ptr<Channel> channel) {
channel_ = channel;
}
// Assembles the client's payload, sends it and presents the response back
// from the server.
AppInstance* goRegister(const std::string& appCode) {
std::unique_ptr<ApplicationRegisterService::Stub> stub_;
stub_ = ApplicationRegisterService::NewStub(channel_) ;
// Data we are sending to the server.
Application request;
request.set_applicationcode( appCode );
// Container for the data we expect from the server.
ApplicationMapping reply;
// Context for the client. It could be used to convey extra information to
// the server and/or tweak certain RPC behaviors.
ClientContext context;
KeyWithIntegerValue kwiv;
// The actual RPC.
Status status = stub_->applicationCodeRegister(&context, request, &reply);
AppInstance* appInstance = (AppInstance*)malloc(sizeof(AppInstance));
// Act upon its status.
if (status.ok()) {
kwiv = reply.application();
appInstance->applicationId = kwiv.value();
return appInstance;
}
return NULL;
}
// Assembles the client's payload, sends it and presents the response back
// from the server.
AppInstance* goRegisterInstance(
std::string agentUUID,
std::string osName,
std::string hostname,
std::string ipv4s,
int applicationId,
long registerTime,
int processNo
) {
std::unique_ptr<InstanceDiscoveryService::Stub> stub_;
stub_ = InstanceDiscoveryService::NewStub(channel_);
// Data we are sending to the server.
ApplicationInstance request;
request.set_applicationid( applicationId );
request.set_agentuuid( agentUUID );
request.set_registertime( registerTime );
OSInfo* osinfo = new OSInfo;
request.set_allocated_osinfo( osinfo );
osinfo->set_osname( osName );
osinfo->set_hostname( hostname );
osinfo->set_processno( processNo );
osinfo->add_ipv4s( ipv4s );
AppInstance* appInstancestruct = (AppInstance*)malloc(sizeof(AppInstance));
// Container for the data we expect from the server.
ApplicationInstanceMapping reply;
// Context for the client. It could be used to convey extra information to
// the server and/or tweak certain RPC behaviors.
ClientContext context;
// The actual RPC.
Status status = stub_->registerInstance(&context, request, &reply);
//free OSInfo
//delete osinfo;
// Act upon its status.
if (status.ok()) {
appInstancestruct->applicationId = reply.applicationid();
appInstancestruct->applicationInstanceId = reply.applicationinstanceid();
return appInstancestruct;
}
return NULL;
}
void sendTrace( TraceSegmentObjectStruct* traceSegment ) {
std::unique_ptr<TraceSegmentService::Stub> stub_;
stub_ = TraceSegmentService::NewStub(channel_);
// Data we are sending to the server.
UpstreamSegment request ;
//UniqueId
UniqueId* uniqueId;
uniqueId = request.add_globaltraceids();
comListNode* com_list = traceSegment->traceSegmentIdList->head;
while(com_list != NULL)
{
uniqueId->add_idparts(com_list->data->idParts);
com_list = com_list->next;
}
if( traceSegment->segment ){
request.set_segment(traceSegment->segment);
Downstream reply;
ClientContext context;
grpc_connectivity_state state = channel_->GetState(false);
if( state == GRPC_CHANNEL_TRANSIENT_FAILURE ){
return ;
}
std::unique_ptr<ClientWriter<UpstreamSegment> > writer( stub_->collect(&context, &reply));
writer->Write(request);
writer->WritesDone();
writer->Finish();
}
}
private:
std::shared_ptr<Channel> channel_;
};
int goSkyGrpc(char *host, int method, ParamDataStruct* paramData, void (*callfuct)( AppInstance* ) ) {
std::shared_ptr<Channel> channel = grpc::CreateChannel(
host, grpc::InsecureChannelCredentials());
static GreeterClient greeter(channel);
switch (method) {
case METHOD__GO_REGISTER:
{
std::string appCode( paramData->registerParam->appCode);
callfuct(greeter.goRegister(appCode));
}
break;
case METHOD__GO_REGISTER_INSTANCE:
{
std::string agentUUID(paramData->registerInstanceParam->agentUUID);
std::string osName(paramData->registerInstanceParam->osName);
std::string hostname(paramData->registerInstanceParam->hostname);
std::string ipv4s(paramData->registerInstanceParam->ipv4s);
int applicationId = paramData->registerInstanceParam->applicationId;
long registerTime = paramData->registerInstanceParam->registerTime;
int processNo = paramData->registerInstanceParam->processNo;
callfuct(
greeter.goRegisterInstance(
agentUUID,
osName,
hostname,
ipv4s,
applicationId,
registerTime,
processNo
)
);
}
break;
case METHOD__SEND_TRACE_SEGMENT:
{
greeter.sendTrace( paramData->sendTraceSegmentParam->traceSegment );
}
break;
default:
return 0;
break;
}
return 1;
}
......@@ -8,8 +8,10 @@
[skywalking]
skywalking.app_code = mapi
skywalking.app_code = api
skywalking.sampling_rate = 99.22;
skywalking.log_path = /tmp/log
skywalking.header_client_ip_name = HTTP_DD_REAL_IP
skywalking.auto_open = On
\ No newline at end of file
skywalking.auto_open = On
skywalking.send_type = 1
skywalking.grpc_trace = 127.0.0.1:50051
\ No newline at end of file
......@@ -24,7 +24,7 @@
extern zend_module_entry skywalking_module_entry;
#define phpext_skywalking_ptr &skywalking_module_entry
#define PHP_SKYWALKING_VERSION "0.1.0" /* Replace with version number for your extension */
#define PHP_SKYWALKING_VERSION "0.2.0" /* Replace with version number for your extension */
#ifdef PHP_WIN32
# define PHP_SKYWALKING_API __declspec(dllexport)
......@@ -44,25 +44,58 @@ extern zend_module_entry skywalking_module_entry;
#define SKY_G(v) (skywalking_globals.v)
#endif
#define SKYWALKING_TRACEID "ts" //TraceId
#define SKYWALKING_STARTTIME "st"//开始时间
#define SKYWALKING_ENDTIME "et" //结束时间
#define SKYWALKING_APP_CODE "ac"// App Code
#define SKYWALKING_FATHER_NODE_DATA "rs"//父节点数据
#define SKYWALKING_SPANS_NODE_DATA "ss"//span节点数据集合
#define SKYWALKING_DISTRIBUTED_TRACEIDS "gt" //DistributedTraceIds
#define SKYWALKING_SPAN_ID "si"//SpanId
#define SKYWALKING_PEERHOST "ph"//PeerHost
#define SKYWALKING_FATHER_SPAN_ID "ps"//父节点传过来的SpanId
#define SKYWALKING_SPAN_SERVER_URI "on" // Span 的服务URI
#define SKYWALKING_SPAN_STRING_PARAM "ts" //Span 的字符串型参数
#define SKYWALKING_SPAN_BOOL_PARAM "tb" //Span 的字符串型参数
#define SKYWALKING_SPAN_INT_PARAM "ti" //Span 的字符串型参数
#define SKYWALKING_SPAN_LOG "lo"//Span 的日志
int ski_zval_key = 0;
#define SKY_MAKE_NULL_ARRAY_NAME(i_zval_key) null_array_##i_zval_key
#define S_SEND_TYPE_CLOSE (1<<0L)
#define S_SEND_TYPE_GRPC (1<<1L)
#define S_SEND_TYPE_WRITE (1<<2L)
#define USE_PARENT_TRACE_ID 1
#define DONOT_USE_PARENT_TRACE_ID 0
#define SKYWALKING_SEGMENT "sg" //全部段节点
#define SKYWALKING_DISTRIBUTED_TRACEIDS "gt"//DistributedTraceIds
#define SKYWALKING_TRACE_SEGMENT_ID "ts"//本次请求id
#define SKYWALKING_APPLICATION_ID "ai"//app id
#define SKYWALKING_APPLICATION_INSTANCE_ID "ii"//实例id
#define SKYWALKING_FATHER_NODE_DATA "rs" //父节点数据
#define SKYWALKING_SPANS_NODE_DATA "ss" //span节点数据集合
#define SKYWALKING_PARENT_TRACE_SEGMENT_ID "ts" //本次请求id
#define SKYWALKING_PARENT_APPLICATION_ID "ai"//app id
#define SKYWALKING_PARENT_SPAN_ID "si"//spanid
#define SKYWALKING_PARENT_SERVICE_ID "vi"//
#define SKYWALKING_PARENT_SERVICE_NAME "vn"
#define SKYWALKING_NETWORK_ADDRESS_ID "ni"
#define SKYWALKING_NETWORK_ADDRESS "nn"
#define SKYWALKING_ENTRY_APPLICATION_INSTANCE_ID "ea"
#define SKYWALKING_ENTRY_SERVICE_ID "ei"
#define SKYWALKING_ENTRY_SERVICE_NAME "en"
#define SKYWALKING_REF_TYPE_VALUE "rv"
#define SKYWALKING_SPAN_ID "si" //SpanId
#define SKYWALKING_SPAN_TYPE_VALUE "tv"
#define SKYWALKING_SPAN_LAYER_VALUE "lv"
#define SKYWALKING_FATHER_SPAN_ID "ps" //父节点传过来的SpanId
#define SKYWALKING_STARTTIME "st" //开始时间
#define SKYWALKING_ENDTIME "et" //结束时间
#define SKYWALKING_COMPONENT_ID "ci"
#define SKYWALKING_COMPONENT_NAME "cn"
#define SKYWALKING_OPERATION_NAME_ID "oi"
#define SKYWALKING_OPERATION_NAME "on"// Span 的服务URI
#define SKYWALKING_PEER_ID "pi"
#define SKYWALKING_PEER "pn"
#define SKYWALKING_IS_ERROR "ie"
#define SKYWALKING_TAGS "to"
#define SKYWALKING_LOGS "lo"
#define SKYWALKING_KEY "k"
#define SKYWALKING_VALUE "v"
#define SKYWALKING_TIME "ti"
#define SKYWALKING_LOG_DATA "ld"
#define RAND_RANGE(__n, __min, __max, __tmax) \
(__n) = ((__min) + (zend_long) ((double) ( (double) (__max) - (__min) + 1.0) * ((__n) / ((__tmax) + 1.0))))
......@@ -88,40 +121,54 @@ void *SKY_UPDATE_PROPERTY(zend_class_entry *cls, zval *tp, const char *name, siz
array_init(&null_array);
zend_update_property(cls, tp, name, name_length, &null_array);
}
static void *write_log_text(char *text);
static char *sky_json_encode(zval *parameter);
static int _php_filter_validate_domain(char * domain, int len, zend_long flags) ;
static int _php_filter_validate_ipv4(char *str, size_t str_len, int *ip);
static int _php_filter_validate_ipv6(char *str, size_t str_len);
static int _php_filter_validate_url(char *value);
static zval *sky_instance(zval *this_ptr, const char *appCode);
static void date_register_classes(TSRMLS_D);
static void _init(const char *appCode, zval *this_ptr);
static char *build_SWheader_value(const char *peer_host, zval *this_ptr);
static zval *receive_SWHeader_from_caller(zval *this_ptr);
static char *build_SWheader_value(const char *peer_host);
static zval receive_SWHeader_from_caller();
static char *get_millisecond();
static char *uniqid();
static char *make_trace_id();
static zend_always_inline zend_uchar is_sampling(zval *this_ptr);
static char *generate_trace_id(zval *this_ptr);
static zend_always_inline zend_uchar is_sampling();
static char *generate_trace_id();
static char *get_ip();
static char *get_page_url_and_peer();
static long generate_span_id(zval *this_ptr);
static char *generate_distributed_trace_ids(zval *this_ptr);
static void *write_log(zval *this_ptr, char *text);
static zval *set_span_nodes_data(zval *this_ptr, zval *node_data);
static char *sky_finishAll();
static long generate_span_id();
static void *write_log( char *text);
static zval *set_span_nodes_data(zval *node_data);
static long sky_array_unshift(zval *stack, zval *var);
static void set_sampling_rate(zval *this_ptr, double degrees);
static void start_span_of_curl(char *peer_host, zval *headers, zval *this_pr);
static void set_span_param_of_curl(char *peer_host, zval *this_pr);
static void make_span_curl_header(char *peer_host, zval *headers, zval *this_pr);
static void set_sampling_rate(double degrees);
static void set_span_param_of_curl(char *peer_host);
static void make_span_curl_header(char *peer_host, zval *headers);
static void start_span(zval *this_pr);
static int is_auto_open();
static void end_span_of_curl(zval *this_ptr,zval *curl);
void accel_sky_curl_init(INTERNAL_FUNCTION_PARAMETERS);
void accel_sky_curl_setopt(INTERNAL_FUNCTION_PARAMETERS);
void accel_sky_curl_exec(INTERNAL_FUNCTION_PARAMETERS);
void list_poll(comList* myroot);
static void *sky_flush_all();
static char* _get_current_machine_ip();
static int get_app_instance_id();
static int get_app_id();
static char *generate_parent_info_from_header(char *header_name);
static void start_node_span_of_curl();
static char *generate_parent_trace_id();
static zval* generate_trace_id_for_array(int use_parent_tid, zval* z_trace_id);
static char* _entry_app_name();
static char *generate_distributed_trace_ids();
static int _entry_app_instance_id();
static void end_node_span_of_curl(zval *curl);
static void* send_grpc_param(zval *all_node_data);
static comList* create_com_list();
static long _entry_app_name_operation_id();
static long _parent_appname_operation_id();
static int sky_live_pthread(pthread_t tid);
static int add_com_list(comList *com_list, UniqueIdStruct* data);
static void (*orig_curl_init)(INTERNAL_FUNCTION_PARAMETERS) = NULL;
static void (*orig_curl_setopt)(INTERNAL_FUNCTION_PARAMETERS) = NULL;
static void (*orig_curl_exec)(INTERNAL_FUNCTION_PARAMETERS) = NULL;
/*
Declare any global variables you may need between the BEGIN
and END macros here:
......@@ -130,8 +177,10 @@ ZEND_BEGIN_MODULE_GLOBALS(skywalking)
char *global_log_path;
char *global_header_client_ip_name;
char *global_app_code;
long global_send_type;
zend_bool global_auto_open;
double global_sampling_rate;
char *global_app_grpc_trace;
ZEND_END_MODULE_GLOBALS(skywalking)
extern ZEND_DECLARE_MODULE_GLOBALS(skywalking);
......@@ -146,6 +195,41 @@ extern ZEND_DECLARE_MODULE_GLOBALS(skywalking);
ZEND_TSRMLS_CACHE_EXTERN()
#endif
#ifdef __unix
#ifdef __linux
#define SKY_OS_NAME "Linux"
#endif
#ifdef __sun
#ifdef __sparc
#define SKY_OS_NAME "Sun SPARC"
#else
#define SKY_OS_NAME "Sun X86"
#endif
#endif
#ifdef _AIX
#define SKY_OS_NAME "AIX"
#endif
#else
#ifdef WINVER
#define SKY_OS_NAME "Windows"
#else
#define SKY_OS_NAME "Unknown"
#endif
#endif
#endif /* PHP_SKYWALKING_H */
......
syntax = "proto3";
option java_multiple_files = true;
option java_package = "org.apache.skywalking.apm.network.proto";
//register service for ApplicationCode, this service is called when service starts.
service ApplicationRegisterService {
rpc applicationCodeRegister (Application) returns (ApplicationMapping) {
}
}
message KeyWithIntegerValue {
string key = 1;
int32 value = 2;
}
message Application {
string applicationCode = 1;
}
message ApplicationMapping {
KeyWithIntegerValue application = 1;
}
syntax = "proto3";
option java_multiple_files = true;
option java_package = "org.apache.skywalking.apm.network.proto";
service InstanceDiscoveryService {
rpc registerInstance (ApplicationInstance) returns (ApplicationInstanceMapping) {
}
}
message ApplicationInstance {
int32 applicationId = 1;
string agentUUID = 2;
int64 registerTime = 3;
OSInfo osinfo = 4;
}
message ApplicationInstanceMapping {
int32 applicationId = 1;
int32 applicationInstanceId = 2;
}
message ApplicationInstanceRecover {
int32 applicationId = 1;
int32 applicationInstanceId = 2;
int64 registerTime = 3;
OSInfo osinfo = 4;
}
message ApplicationInstanceHeartbeat {
int32 applicationInstanceId = 1;
int64 heartbeatTime = 2;
}
message OSInfo {
string osName = 1;
string hostname = 2;
int32 processNo = 3;
repeated string ipv4s = 4;
}
//discovery service for ServiceName by Network address or application code
service ServiceNameDiscoveryService {
rpc discovery (ServiceNameCollection) returns (ServiceNameMappingCollection) {
}
}
message ServiceNameCollection {
repeated ServiceNameElement elements = 1;
}
message ServiceNameMappingCollection {
repeated ServiceNameMappingElement elements = 1;
}
message ServiceNameMappingElement {
int32 serviceId = 1;
ServiceNameElement element = 2;
}
message ServiceNameElement {
string serviceName = 1;
int32 applicationId = 2;
}
syntax = "proto3";
option java_multiple_files = true;
option java_package = "org.apache.skywalking.apm.network.proto";
service TraceSegmentService {
rpc collect (stream UpstreamSegment) returns (Downstream) {
}
}
message Downstream {
}
message KeyWithStringValue {
string key = 1;
string value = 2;
}
message UpstreamSegment {
repeated UniqueId globalTraceIds = 1;
bytes segment = 2; // the byte array of TraceSegmentObject
}
message UniqueId {
repeated int64 idParts = 1;
}
message TraceSegmentObject {
UniqueId traceSegmentId = 1;
repeated SpanObject spans = 2;
int32 applicationId = 3;
int32 applicationInstanceId = 4;
bool isSizeLimited = 5;
}
message TraceSegmentReference {
RefType refType = 1;
UniqueId parentTraceSegmentId = 2;
int32 parentSpanId = 3;
int32 parentApplicationInstanceId = 4;
string networkAddress = 5;
int32 networkAddressId = 6;
int32 entryApplicationInstanceId = 7;
string entryServiceName = 8;
int32 entryServiceId = 9;
string parentServiceName = 10;
int32 parentServiceId = 11;
}
message SpanObject {
int32 spanId = 1;
int32 parentSpanId = 2;
int64 startTime = 3;
int64 endTime = 4;
repeated TraceSegmentReference refs = 5;
int32 operationNameId = 6;
string operationName = 7;
int32 peerId = 8;
string peer = 9;
SpanType spanType = 10;
SpanLayer spanLayer = 11;
int32 componentId = 12;
string component = 13;
bool isError = 14;
repeated KeyWithStringValue tags = 15;
repeated LogMessage logs = 16;
}
enum RefType {
CrossProcess = 0;
CrossThread = 1;
}
enum SpanType {
Entry = 0;
Exit = 1;
Local = 2;
}
enum SpanLayer {
Unknown = 0;
Database = 1;
RPCFramework = 2;
Http = 3;
MQ = 4;
Cache = 5;
}
message LogMessage {
int64 time = 1;
repeated KeyWithStringValue data = 2;
}
此差异已折叠。
<?php
$file = new SplFileObject('appid.pid', "w");
$written = $file->fwrite("124124");
$file = new SplFileObject('appid.pid');
$aa = $file->current();
var_dump($aa);
exit;
function getfiles($path){
foreach(scandir($path) as $afile)
{
if($afile=='.'||$afile=='..') continue;
if(is_file($path.'/'.$afile)){
echo $afile. "\n";
}
}
} //简单的demo,列出当前目录下所有的文件
getfiles(__DIR__);
exit;
var_dump(base_convert(uniqid(), 16, 10));
getMillisecond();
function getMillisecond()
{
list($t1, $t2) = explode(' ', microtime());
/*$t3 = $t1 * 100000000;
var_dump($t2, substr($t2, -6));
$aa = (float)($t3 . substr($t2, -6));
var_dump( (float)($t3 . substr($t2, -6)));
var_dump( json_encode(array("aaa"=> $aa)));
exit;*/
$millisecond = (float)sprintf('%.0f', (floatval($t1) + floatval($t2)) * 10000);
var_dump( json_encode(array("aaa"=> $millisecond)));
var_dump( $millisecond);
return $millisecond;
}
exit;
var_dump(json_encode(["applicationCode"=>"mapi"]));exit;
exit;
$br = (php_sapi_name() == "cli")? "":"<br>";
if(!extension_loaded('skywalking')) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册