Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php 7.3, 7.4 support #158

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
language: c

env:
- MO_PHP_VERSION=7.4.3
- MO_PHP_VERSION=7.3.2
- MO_PHP_VERSION=7.2.2
- MO_PHP_VERSION=7.1.2
- MO_PHP_VERSION=7.0.16
Expand Down
2 changes: 1 addition & 1 deletion .travis/ext_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fi

if [ "$PHP_MAJOR" -eq "7" ] ;then
#ls -a $MO_EX_DIR |grep memcached || printf "\n" | $PHP_PECL install -f --ignore-errors memcached-3.0.2
ls -a $MO_EX_DIR |grep memcached || (wget http://pecl.php.net/get/memcached-3.0.2.tgz && tar xf memcached-3.0.2.tgz && cd memcached-3.0.2 && $PHP_IZE && ./configure --with-php-config=$PHP_CONF --disable-memcached-sasl && make && make install)
ls -a $MO_EX_DIR |grep memcached || (wget http://pecl.php.net/get/memcached-3.1.0.tgz && tar xf memcached-3.1.0.tgz && cd memcached-3.1.0 && $PHP_IZE && ./configure --with-php-config=$PHP_CONF --disable-memcached-sasl && make && make install)
else
#ls -a $MO_EX_DIR |grep memcached || printf "\n" | $PHP_PECL install -f --ignore-errors memcached-2.2.0
ls -a $MO_EX_DIR |grep 1memcached || (wget http://pecl.php.net/get/memcached-2.2.0.tgz && tar xf memcached-2.2.0.tgz && cd memcached-2.2.0 && $PHP_IZE && ./configure --with-php-config=$PHP_CONF --disable-memcached-sasl && make && make install)
Expand Down
4 changes: 3 additions & 1 deletion .travis/php_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ function build()
# prepare
param_general="--disable-all $param_debug"
param_sapi="--enable-cli --enable-cgi"
if [ ${version:0:3} == "7.3" ]; then
param_ext="--without-libzip"
# hack for PHP 5.2
if [ ${version:0:3} == "5.2" ]; then
elif [ ${version:0:3} == "5.2" ]; then
# pcre: run-tests.php
# spl: spl_autoload_register in trace's tests
param_ext="--with-pcre-regex --enable-spl"
Expand Down
13 changes: 9 additions & 4 deletions molten.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
} \
}while(0)

#if PHP_VERSION_ID < 70300
#define MO_HASH_FLAG_PERSISTENT HASH_FLAG_PERSISTENT
#else
#define MO_HASH_FLAG_PERSISTENT IS_ARRAY_PERSISTENT
#endif

PHP_FUNCTION(molten_curl_setopt);
PHP_FUNCTION(molten_curl_exec);
Expand Down Expand Up @@ -176,16 +181,16 @@ static void molten_reload_curl_function()
orig->common.fn_flags = ZEND_ACC_PUBLIC;
//Set orig handle
if(!strcmp(p->orig_func,"curl_setopt")) {
origin_curl_setopt = pemalloc(sizeof(zend_internal_function), HASH_FLAG_PERSISTENT);
origin_curl_setopt = pemalloc(sizeof(zend_internal_function), MO_HASH_FLAG_PERSISTENT);
memcpy(origin_curl_setopt, orig, sizeof(zend_internal_function));
} else if (!strcmp(p->orig_func,"curl_exec")) {
origin_curl_exec = pemalloc(sizeof(zend_internal_function), HASH_FLAG_PERSISTENT);
origin_curl_exec = pemalloc(sizeof(zend_internal_function), MO_HASH_FLAG_PERSISTENT);
memcpy(origin_curl_exec, orig, sizeof(zend_internal_function));
} else if (!strcmp(p->orig_func,"curl_setopt_array")) {
origin_curl_setopt_array = pemalloc(sizeof(zend_internal_function) , HASH_FLAG_PERSISTENT);
origin_curl_setopt_array = pemalloc(sizeof(zend_internal_function) , MO_HASH_FLAG_PERSISTENT);
memcpy(origin_curl_setopt_array, orig, sizeof(zend_internal_function));
} else if (!strcmp(p->orig_func,"curl_reset")) {
origin_curl_reset = pemalloc(sizeof(zend_internal_function), HASH_FLAG_PERSISTENT);
origin_curl_reset = pemalloc(sizeof(zend_internal_function), MO_HASH_FLAG_PERSISTENT);
memcpy(origin_curl_reset, orig, sizeof(zend_internal_function));
}
function_add_ref(orig);
Expand Down
20 changes: 19 additions & 1 deletion molten_intercept.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static char *convert_args_to_string(mo_frame_t *frame)
int stop = 0;
memset(string, 0x00, ARGS_MAX_LEN);
arg_len = smart_string_len(frame->function) + 1;
string = strncat(string, smart_string_str(frame->function), real_len - 1);
string = strncat(string, smart_string_str(frame->function), arg_len - 1);
string = strncat(string, " ", 1);

for (; i < frame->arg_count; i++) {
Expand Down Expand Up @@ -335,7 +335,13 @@ static char *pcre_common_match(char *pattern, int len, char *subject)
#else
if ((cache = pcre_get_compiled_regex_cache(pattern, len)) != NULL) {
#endif

#if PHP_VERSION_ID >= 70400
zend_string *str = zend_string_init(subject, strlen(subject), 0);
php_pcre_match_impl(cache, str, result, subpats, 0, 0, 0, 0 TSRMLS_CC);
#else
php_pcre_match_impl(cache, subject, strlen(subject), result, subpats, 0, 0, 0, 0 TSRMLS_CC);
#endif
zval *match = NULL;
if (Z_LVAL_P(result) > 0 && MO_Z_TYPE_P(subpats) == IS_ARRAY) {
#if PHP_VERSION_ID >= 70000
Expand Down Expand Up @@ -1171,7 +1177,11 @@ static void mongodb_record(mo_interceptor_t *pit, mo_frame_t *frame)
/* read url from debug info */
zval *obj = frame->object;
int is_temp;
#if PHP_VERSION_ID >= 70400
HashTable *debug_hash = zend_get_properties_for(obj, ZEND_PROP_PURPOSE_DEBUG);
#else
HashTable *debug_hash = Z_OBJDEBUG_P(obj, is_temp);
#endif
zval *uri = NULL;
if (mo_zend_hash_zval_find(debug_hash, "uri", sizeof("uri"), (void **)&uri) == SUCCESS) {
if (uri != NULL && MO_Z_TYPE_P(uri) == IS_STRING) {
Expand Down Expand Up @@ -1208,7 +1218,11 @@ static void mongodb_server_record(mo_interceptor_t *pit, mo_frame_t *frame)
/* read url from debug info */
zval *obj = frame->object;
int is_temp;
#if PHP_VERSION_ID >= 70400
HashTable *debug_hash = zend_get_properties_for(obj, ZEND_PROP_PURPOSE_DEBUG);
#else
HashTable *debug_hash = Z_OBJDEBUG_P(obj, is_temp);
#endif
zval *host = NULL;
zval *port = NULL;
if (mo_zend_hash_zval_find(debug_hash, "host", sizeof("host"), (void **)&host) == SUCCESS) {
Expand Down Expand Up @@ -1342,7 +1356,11 @@ static void es_request_record(mo_interceptor_t *pit, mo_frame_t *frame)
if (MO_Z_TYPE_P(&host) == IS_STRING) {
php_url *url = php_url_parse(Z_STRVAL(host));
if (url != NULL) {
#if PHP_VERSION_ID >= 70400
pit->psb->span_add_ba(span, "sa", "true", frame->exit_time, "es", ZSTR_VAL(url->host), url->port, BA_SA);
#else
pit->psb->span_add_ba(span, "sa", "true", frame->exit_time, "es", url->host, url->port, BA_SA);
#endif

} else {
pit->psb->span_add_ba_ex(span, "php.db.data_source", Z_STRVAL(host), frame->exit_time, pit->pct, BA_NORMAL);
Expand Down
4 changes: 4 additions & 0 deletions php7_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,11 @@ static inline void mo_array_merge(zval *dest, zval *src TSRMLS_DC)
static inline void array_init_persist(zval *arg ZEND_FILE_LINE_DC)
{
ZVAL_NEW_PERSISTENT_ARR(arg);
#if PHP_VERSION_ID < 70300
_zend_hash_init(Z_ARRVAL_P(arg), 0, ZVAL_PTR_DTOR, 1 ZEND_FILE_LINE_RELAY_CC);
#else
_zend_hash_init(Z_ARRVAL_P(arg), 0, ZVAL_PTR_DTOR, 1);
#endif
}

static inline void array_free_persist(zval *arg)
Expand Down
4 changes: 2 additions & 2 deletions tests/bug_connect_error_db_7.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ Warning: mysqli::query(): invalid object or resource mysqli

Warning: mysqli_connect(): (HY000/2002): %s on line 7

Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in %s on line 8
Warning: mysqli_query() expects parameter 1 to be mysqli, %s given in %s on line 8

Warning: mysqli_prepare() expects parameter 1 to be mysqli, boolean given in %s on line 9
Warning: mysqli_prepare() expects parameter 1 to be mysqli, %s given in %s on line 9

Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, null given in %s on line 10

Expand Down
2 changes: 1 addition & 1 deletion tests/molten_005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ include 'mysqli_execute.inc';
mysqli_exec($true_db, "select * from configs_not_exist");
?>
--EXPECTF--
Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in %s on line 10
Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, %s given in %s on line 10
{"traceId":"%s","name":"mysqli_connect","version":"%s","id":"%s","parentId":"%s","timestamp":%d,"duration":%d,"annotations":[{"value":"cs","timestamp":%d,"endpoint":{"serviceName":"test","ipv4":"%s"}},{"value":"cr","timestamp":%d,"endpoint":{"serviceName":"test","ipv4":"%s"}}],"binaryAnnotations":[{"key":"sa","value":"true","endpoint":{"serviceName":"mysql","ipv4":"%s","port":%d}},{"key":"db.instance","value":"%s","endpoint":{"serviceName":"test","ipv4":"%s"}}]}
{"traceId":"%s","name":"mysqli_query","version":"%s","id":"%s","parentId":"%s","timestamp":%d,"duration":%d,"annotations":[{"value":"cs","timestamp":%d,"endpoint":{"serviceName":"test","ipv4":"%s"}},{"value":"cr","timestamp":%d,"endpoint":{"serviceName":"test","ipv4":"%s"}}],"binaryAnnotations":[{"key":"db.statement","value":"select * from configs_not_exist","endpoint":{"serviceName":"test","ipv4":"%s"}},{"key":"db.type","value":"mysql","endpoint":{"serviceName":"test","ipv4":"%s"}},{"key":"sa","value":"true","endpoint":{"serviceName":"mysql","ipv4":"%s","port":%d}},{"key":"db.instance","value":"%s","endpoint":{"serviceName":"test","ipv4":"%s"}}]}
{"traceId":"%s","name":"mysqli_prepare","version":"%s","id":"%s","parentId":"%s","timestamp":%d,"duration":%d,"annotations":[{"value":"cs","timestamp":%d,"endpoint":{"serviceName":"test","ipv4":"%s"}},{"value":"cr","timestamp":%d,"endpoint":{"serviceName":"test","ipv4":"%s"}}],"binaryAnnotations":[{"key":"db.statement","value":"select * from configs_not_exist","endpoint":{"serviceName":"test","ipv4":"%s"}},{"key":"db.type","value":"mysql","endpoint":{"serviceName":"test","ipv4":"%s"}},{"key":"sa","value":"true","endpoint":{"serviceName":"mysql","ipv4":"%s","port":%d}},{"key":"db.instance","value":"%s","endpoint":{"serviceName":"test","ipv4":"%s"}}]}
Expand Down