Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

新增配置参数mq_max_message_length(默认2048); 支持redis扩展的set/setex命令 #351

Merged
merged 3 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 1 config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ if test "$PHP_SKYWALKING" != "no"; then
src/sky_core_span_log.cc \
src/sky_execute.cc \
src/sky_grpc.cc \
src/sky_log.cc \
src/sky_module.cc \
src/sky_plugin_mysqli.cc \
src/sky_pdo.cc \
Expand Down
32 changes: 31 additions & 1 deletion 32 e2e/tests/redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,35 @@ function testRedis() {
$redis->incr($key);
$redis->setnx($key, "test");
$redis->strlen($key);
$redis->set($key, "test");
$redis->set($key, "test", 100);
$redis->set($key, "test", ["nx", "ex" => 200]);
$redis->setex($key, 300, "test");

}
// multiple keys
$redis->mget([$key .'_1', $key . '_2', $key . '_3']);
$redis->getMultiple([$key .'_1', $key . '_2', $key . '_3']);

// uncertain keys
$redis->eval('return {1,2,3};');
$redis->del($key);
$redis->del($key, $key . '_1');
$redis->del([$key, $key . '_1', $key . '_2']);
$redis->delete($key);
$redis->unlink($key);
$redis->exists($key);

// empty commands
$redis->ping();
$redis->pipeline();
$redis->set($key, '1');
$redis->set($key . '_1', '2');
$redis->set($key . '_2', '3');
$redis->exec();

// expire
$redis->expire($key, 3600);
$redis->expireAt($key, time() + 3600);
$redis->pExpireAt($key, time() + 3600);
$redis->setTimeout($key, 3600);
}
3 changes: 3 additions & 0 deletions 3 php_skywalking.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ ZEND_BEGIN_MODULE_GLOBALS(skywalking)

// php error log
zend_bool error_handler_enable;

// message queue
int mq_max_message_length;
ZEND_END_MODULE_GLOBALS(skywalking)

extern ZEND_DECLARE_MODULE_GLOBALS(skywalking);
Expand Down
13 changes: 8 additions & 5 deletions 13 skywalking.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,23 @@ ZEND_DECLARE_MODULE_GLOBALS(skywalking)

struct service_info *s_info = nullptr;


PHP_INI_BEGIN()
STD_PHP_INI_BOOLEAN("skywalking.enable", "0", PHP_INI_ALL, OnUpdateBool, enable, zend_skywalking_globals, skywalking_globals)
STD_PHP_INI_ENTRY("skywalking.version", "8", PHP_INI_ALL, OnUpdateLong, version, zend_skywalking_globals, skywalking_globals)
STD_PHP_INI_ENTRY("skywalking.app_code", "hello_skywalking", PHP_INI_ALL, OnUpdateString, app_code, zend_skywalking_globals, skywalking_globals)
STD_PHP_INI_ENTRY("skywalking.authentication", "", PHP_INI_ALL, OnUpdateString, authentication, zend_skywalking_globals, skywalking_globals)
STD_PHP_INI_ENTRY("skywalking.grpc", "127.0.0.1:11800", PHP_INI_ALL, OnUpdateString, grpc, zend_skywalking_globals, skywalking_globals)
STD_PHP_INI_ENTRY("skywalking.grpc_tls_enable", "0", PHP_INI_ALL, OnUpdateBool, grpc_tls_enable, zend_skywalking_globals, skywalking_globals)
STD_PHP_INI_BOOLEAN("skywalking.grpc_tls_enable", "0", PHP_INI_ALL, OnUpdateBool, grpc_tls_enable, zend_skywalking_globals, skywalking_globals)
STD_PHP_INI_ENTRY("skywalking.grpc_tls_pem_root_certs", "", PHP_INI_ALL, OnUpdateString, grpc_tls_pem_root_certs, zend_skywalking_globals, skywalking_globals)
STD_PHP_INI_ENTRY("skywalking.grpc_tls_pem_private_key", "", PHP_INI_ALL, OnUpdateString, grpc_tls_pem_private_key, zend_skywalking_globals, skywalking_globals)
STD_PHP_INI_ENTRY("skywalking.grpc_tls_pem_cert_chain", "", PHP_INI_ALL, OnUpdateString, grpc_tls_pem_cert_chain, zend_skywalking_globals, skywalking_globals)

STD_PHP_INI_ENTRY("skywalking.log_enable", "0", PHP_INI_ALL, OnUpdateBool, log_enable, zend_skywalking_globals, skywalking_globals)
STD_PHP_INI_BOOLEAN("skywalking.log_enable", "0", PHP_INI_ALL, OnUpdateBool, log_enable, zend_skywalking_globals, skywalking_globals)
STD_PHP_INI_ENTRY("skywalking.log_path", "/tmp/skywalking-php.log", PHP_INI_ALL, OnUpdateString, log_path, zend_skywalking_globals, skywalking_globals)

STD_PHP_INI_ENTRY("skywalking.error_handler_enable", "0", PHP_INI_ALL, OnUpdateBool, error_handler_enable, zend_skywalking_globals, skywalking_globals)
STD_PHP_INI_BOOLEAN("skywalking.error_handler_enable", "0", PHP_INI_ALL, OnUpdateBool, error_handler_enable, zend_skywalking_globals, skywalking_globals)

STD_PHP_INI_ENTRY("skywalking.mq_max_message_length", "20480", PHP_INI_ALL, OnUpdateLong, mq_max_message_length, zend_skywalking_globals, skywalking_globals)

PHP_INI_END()

Expand All @@ -71,6 +72,9 @@ static void php_skywalking_init_globals(zend_skywalking_globals *skywalking_glob

// php error log
skywalking_globals->error_handler_enable = 0;

// message queue
skywalking_globals->mq_max_message_length = 0;
}

PHP_FUNCTION (skywalking_trace_id) {
Expand Down Expand Up @@ -162,7 +166,6 @@ PHP_MSHUTDOWN_FUNCTION (skywalking) {

PHP_RINIT_FUNCTION(skywalking)
{

#if defined(COMPILE_DL_SKYWALKING) && defined(ZTS)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
Expand Down
1 change: 0 additions & 1 deletion 1 src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ struct service_info {
char service_instance[0x400];

boost::interprocess::message_queue *mq;
int mq_msg_size = 20480;
};

#endif //SKYWALKING_COMMON_H
22 changes: 6 additions & 16 deletions 22 src/manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
#include <boost/interprocess/ipc/message_queue.hpp>

#include "php_skywalking.h"
#include "sky_log.h"

static std::ofstream sky_log;
std::queue<std::string> messageQueue;
static pthread_mutex_t mx = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
Expand All @@ -46,9 +46,6 @@ extern struct service_info *s_info;

Manager::Manager(const ManagerOptions &options, struct service_info *info) {

if (SKYWALKING_G(log_enable)) {
sky_log.open(SKYWALKING_G(log_path), std::ios::app);
}

std::thread th(login, options, info);
th.detach();
Expand All @@ -59,7 +56,7 @@ Manager::Manager(const ManagerOptions &options, struct service_info *info) {
// std::thread s(sender, options);
// s.detach();

logger("the apache skywalking php plugin mounted");
sky_log("the apache skywalking php plugin mounted");
}

void Manager::login(const ManagerOptions &options, struct service_info *info) {
Expand Down Expand Up @@ -162,7 +159,7 @@ void Manager::login(const ManagerOptions &options, struct service_info *info) {

while (true) {
std::string data;
data.resize(20480);
data.resize(SKYWALKING_G(mq_max_message_length));
size_t msg_size;
unsigned msg_priority;
mq.receive(&data[0], data.size(), msg_size, msg_priority);
Expand All @@ -177,14 +174,14 @@ void Manager::login(const ManagerOptions &options, struct service_info *info) {
google::protobuf::util::MessageToJsonString(msg, &json_str, opt);
bool status = writer->Write(msg);
if (status) {
logger("write success " + json_str);
sky_log("write success " + json_str);
} else {
logger("write fail " + json_str);
sky_log("write fail " + json_str);
break;
}
}
} catch (boost::interprocess::interprocess_exception &ex) {
logger(ex.what());
sky_log(ex.what());
php_error(E_WARNING, "%s %s", "[skywalking] open queue fail ", ex.what());
}
}
Expand Down Expand Up @@ -252,10 +249,3 @@ std::string Manager::generateUUID() {

return res;
}


void Manager::logger(const std::string &log) {
if (SKYWALKING_G(log_enable) && sky_log.is_open()) {
sky_log << log << std::endl;
}
}
18 changes: 18 additions & 0 deletions 18 src/sky_log.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <string>
#include <sstream>
#include <ostream>
#include <iostream>
#include <fstream>
#include "php_skywalking.h"

static std::ofstream log_fs;

void sky_log(std::string log) {
if (SKYWALKING_G(log_enable) && !log_fs.is_open()) {
log_fs.open(SKYWALKING_G(log_path), std::ios::app);
}

if (log_fs.is_open()) {
log_fs << log << std::endl;
}
}
8 changes: 8 additions & 0 deletions 8 src/sky_log.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <string>

#ifndef SKYWALKING_SKY_LOG_H
#define SKYWALKING_SKY_LOG_H

void sky_log(std::string log);

#endif
11 changes: 10 additions & 1 deletion 11 src/sky_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "sky_execute.h"
#include "manager.h"
#include "sky_plugin_error.h"
#include "sky_log.h"

extern struct service_info *s_info;

Expand Down Expand Up @@ -84,7 +85,7 @@ void sky_module_init() {
boost::interprocess::create_only,
"skywalking_queue",
1024,
20480,
SKYWALKING_G(mq_max_message_length),
boost::interprocess::permissions(0666)
);
} catch (boost::interprocess::interprocess_exception &ex) {
Expand Down Expand Up @@ -178,13 +179,21 @@ void sky_request_flush(zval *response, uint64_t request_id) {
std::string msg = segment->marshal();
delete segment;

int msg_length = static_cast<int>(msg.size());
int max_length = SKYWALKING_G(mq_max_message_length);
if (msg_length > max_length) {
sky_log("message is too big: " + std::to_string(msg_length) + ", mq_max_message_length=" + std::to_string(max_length));
return;
}

try {
boost::interprocess::message_queue mq(
boost::interprocess::open_only,
"skywalking_queue"
);
mq.send(msg.data(), msg.size(), 0);
} catch (boost::interprocess::interprocess_exception &ex) {
sky_log("sky_request_flush message_queue ex" + std::string(ex.what()));
php_error(E_WARNING, "%s %s", "[skywalking] open queue fail ", ex.what());
}
}
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.