Skip to content

Instantly share code, notes, and snippets.

@adsr
Created November 4, 2019 16:52
Show Gist options
  • Select an option

  • Save adsr/f4e5db29aae01e81a834b4a6d432fa87 to your computer and use it in GitHub Desktop.

Select an option

Save adsr/f4e5db29aae01e81a834b4a6d432fa87 to your computer and use it in GitHub Desktop.
diff --git a/ext/mysqlnd/mysqlnd.h b/ext/mysqlnd/mysqlnd.h
index 7cc7cc96e6..e379488118 100644
--- a/ext/mysqlnd/mysqlnd.h
+++ b/ext/mysqlnd/mysqlnd.h
@@ -306,21 +306,21 @@ PHPAPI void _mysqlnd_get_client_stats(MYSQLND_STATS * stats, zval *return_valu
#define MYSQLND_METHOD_PRIVATE(class, method) mysqlnd_##class##_##method##_priv
ZEND_BEGIN_MODULE_GLOBALS(mysqlnd)
char * debug; /* The actual string */
char * trace_alloc_settings; /* The actual string */
MYSQLND_DEBUG * dbg; /* The DBG object for standard tracing */
MYSQLND_DEBUG * trace_alloc; /* The DBG object for allocation tracing */
zend_long net_cmd_buffer_size;
zend_long net_read_buffer_size;
zend_long log_mask;
- zend_long net_read_timeout;
+ double net_read_timeout;
zend_long mempool_default_size;
zend_long debug_emalloc_fail_threshold;
zend_long debug_ecalloc_fail_threshold;
zend_long debug_erealloc_fail_threshold;
zend_long debug_malloc_fail_threshold;
zend_long debug_calloc_fail_threshold;
zend_long debug_realloc_fail_threshold;
char * sha256_server_public_key;
zend_bool fetch_data_copy;
zend_bool collect_statistics;
diff --git a/ext/mysqlnd/mysqlnd_net.c b/ext/mysqlnd/mysqlnd_net.c
index 6fb9c5fde2..de6d2fd536 100644
--- a/ext/mysqlnd/mysqlnd_net.c
+++ b/ext/mysqlnd/mysqlnd_net.c
@@ -257,23 +257,23 @@ MYSQLND_METHOD(mysqlnd_net, open_tcp_or_unix)(MYSQLND_NET * const net, const cha
static void
MYSQLND_METHOD(mysqlnd_net, post_connect_set_opt)(MYSQLND_NET * const net,
const char * const scheme, const size_t scheme_len,
MYSQLND_STATS * const conn_stats, MYSQLND_ERROR_INFO * const error_info)
{
php_stream * net_stream = net->data->m.get_stream(net);
DBG_ENTER("mysqlnd_net::post_connect_set_opt");
if (net_stream) {
if (net->data->options.timeout_read) {
struct timeval tv;
- DBG_INF_FMT("setting %u as PHP_STREAM_OPTION_READ_TIMEOUT", net->data->options.timeout_read);
- tv.tv_sec = net->data->options.timeout_read;
- tv.tv_usec = 0;
+ DBG_INF_FMT("setting %f as PHP_STREAM_OPTION_READ_TIMEOUT", net->data->options.timeout_read);
+ tv.tv_sec = (int)net->data->options.timeout_read;
+ tv.tv_usec = (int)(net->data->options.timeout_read * 1000000.0) % 1000000;
php_stream_set_option(net_stream, PHP_STREAM_OPTION_READ_TIMEOUT, 0, &tv);
}
if (!memcmp(scheme, "tcp://", sizeof("tcp://") - 1)) {
/* TCP -> Set TCP_NODELAY */
mysqlnd_set_sock_no_delay(net_stream);
/* TCP -> Set SO_KEEPALIVE */
mysqlnd_set_sock_keepalive(net_stream);
}
}
@@ -812,25 +812,25 @@ MYSQLND_METHOD(mysqlnd_net, set_client_option)(MYSQLND_NET * const net, enum mys
default:
DBG_INF("default = MYSQLND_SSL_PEER_DEFAULT_ACTION");
val = MYSQLND_SSL_PEER_DEFAULT;
break;
}
net->data->options.ssl_verify_peer = val;
break;
}
case MYSQL_OPT_READ_TIMEOUT:
DBG_INF("MYSQL_OPT_READ_TIMEOUT");
- net->data->options.timeout_read = *(unsigned int*) value;
+ net->data->options.timeout_read = *(double*) value;
break;
case MYSQL_OPT_WRITE_TIMEOUT:
DBG_INF("MYSQL_OPT_WRITE_TIMEOUT");
- net->data->options.timeout_write = *(unsigned int*) value;
+ net->data->options.timeout_write = *(double*) value;
break;
case MYSQL_OPT_COMPRESS:
net->data->options.flags |= MYSQLND_NET_FLAG_USE_COMPRESSION;
break;
case MYSQL_SERVER_PUBLIC_KEY:
{
zend_bool pers = net->persistent;
if (net->data->options.sha256_server_public_key) {
mnd_pefree(net->data->options.sha256_server_public_key, pers);
}
@@ -983,23 +983,23 @@ MYSQLND_METHOD(mysqlnd_net, enable_ssl)(MYSQLND_NET * const net)
get rid of the context. we are persistent and if this is a real pconn used by mysql/mysqli,
then the context would not survive cleaning of EG(regular_list), where it is registered, as a
resource. What happens is that after this destruction any use of the network will mean usage
of the context, which means usage of already freed memory, bad. Actually we don't need this
context anymore after we have enabled SSL on the connection. Thus it is very simple, we remove it.
*/
php_stream_context_set(net_stream, NULL);
if (net->data->options.timeout_read) {
struct timeval tv;
- DBG_INF_FMT("setting %u as PHP_STREAM_OPTION_READ_TIMEOUT", net->data->options.timeout_read);
- tv.tv_sec = net->data->options.timeout_read;
- tv.tv_usec = 0;
+ DBG_INF_FMT("setting %f as PHP_STREAM_OPTION_READ_TIMEOUT", net->data->options.timeout_read);
+ tv.tv_sec = (int)net->data->options.timeout_read;
+ tv.tv_usec = (int)(net->data->options.timeout_read * 1000000.0) % 1000000;
php_stream_set_option(net_stream, PHP_STREAM_OPTION_READ_TIMEOUT, 0, &tv);
}
DBG_RETURN(PASS);
#else
DBG_ENTER("mysqlnd_net::enable_ssl");
DBG_INF("MYSQLND_SSL_SUPPORTED is not defined");
DBG_RETURN(PASS);
#endif
}
@@ -1086,30 +1086,31 @@ MYSQLND_METHOD(mysqlnd_net, close_stream)(MYSQLND_NET * const net, MYSQLND_STATS
DBG_VOID_RETURN;
}
/* }}} */
/* {{{ mysqlnd_net::init */
static enum_func_status
MYSQLND_METHOD(mysqlnd_net, init)(MYSQLND_NET * const net, MYSQLND_STATS * const stats, MYSQLND_ERROR_INFO * const error_info)
{
unsigned int buf_size;
+ double timeout;
DBG_ENTER("mysqlnd_net::init");
buf_size = MYSQLND_G(net_cmd_buffer_size); /* this is long, cast to unsigned int*/
net->data->m.set_client_option(net, MYSQLND_OPT_NET_CMD_BUFFER_SIZE, (char *) &buf_size);
buf_size = MYSQLND_G(net_read_buffer_size); /* this is long, cast to unsigned int*/
net->data->m.set_client_option(net, MYSQLND_OPT_NET_READ_BUFFER_SIZE, (char *)&buf_size);
- buf_size = MYSQLND_G(net_read_timeout); /* this is long, cast to unsigned int*/
- net->data->m.set_client_option(net, MYSQL_OPT_READ_TIMEOUT, (char *)&buf_size);
+ timeout = MYSQLND_G(net_read_timeout); /* this is a double */
+ net->data->m.set_client_option(net, MYSQL_OPT_READ_TIMEOUT, (char *)&timeout);
DBG_RETURN(PASS);
}
/* }}} */
/* {{{ mysqlnd_net::dtor */
static void
MYSQLND_METHOD(mysqlnd_net, dtor)(MYSQLND_NET * const net, MYSQLND_STATS * const stats, MYSQLND_ERROR_INFO * const error_info)
{
diff --git a/ext/mysqlnd/mysqlnd_structs.h b/ext/mysqlnd/mysqlnd_structs.h
index a7c892b48d..ba8229f6dc 100644
--- a/ext/mysqlnd/mysqlnd_structs.h
+++ b/ext/mysqlnd/mysqlnd_structs.h
@@ -229,22 +229,22 @@ typedef struct st_mysqlnd_session_options
#ifdef MYSQLND_STRING_TO_INT_CONVERSION
zend_bool int_and_float_native;
#endif
} MYSQLND_SESSION_OPTIONS;
typedef struct st_mysqlnd_vio_options
{
/* timeouts */
unsigned int timeout_connect;
- unsigned int timeout_read;
- unsigned int timeout_write;
+ double timeout_read;
+ double timeout_write;
size_t net_read_buffer_size;
/* SSL information */
char *ssl_key;
char *ssl_cert;
char *ssl_ca;
char *ssl_capath;
char *ssl_cipher;
char *ssl_passphrase;
diff --git a/ext/mysqlnd/mysqlnd_vio.c b/ext/mysqlnd/mysqlnd_vio.c
index 50db782be6..3b0a8b4d72 100644
--- a/ext/mysqlnd/mysqlnd_vio.c
+++ b/ext/mysqlnd/mysqlnd_vio.c
@@ -243,23 +243,23 @@ MYSQLND_METHOD(mysqlnd_vio, open_tcp_or_unix)(MYSQLND_VIO * const vio, const MYS
/* {{{ mysqlnd_vio::post_connect_set_opt */
static void
MYSQLND_METHOD(mysqlnd_vio, post_connect_set_opt)(MYSQLND_VIO * const vio, const MYSQLND_CSTRING scheme,
MYSQLND_STATS * const conn_stats, MYSQLND_ERROR_INFO * const error_info)
{
php_stream * net_stream = vio->data->m.get_stream(vio);
DBG_ENTER("mysqlnd_vio::post_connect_set_opt");
if (net_stream) {
if (vio->data->options.timeout_read) {
struct timeval tv;
- DBG_INF_FMT("setting %u as PHP_STREAM_OPTION_READ_TIMEOUT", vio->data->options.timeout_read);
- tv.tv_sec = vio->data->options.timeout_read;
- tv.tv_usec = 0;
+ DBG_INF_FMT("setting %f as PHP_STREAM_OPTION_READ_TIMEOUT", vio->data->options.timeout_read);
+ tv.tv_sec = (int)vio->data->options.timeout_read;
+ tv.tv_usec = (int)(vio->data->options.timeout_read * 1000000.0) % 1000000;
php_stream_set_option(net_stream, PHP_STREAM_OPTION_READ_TIMEOUT, 0, &tv);
}
if (!memcmp(scheme.s, "tcp://", sizeof("tcp://") - 1)) {
/* TCP -> Set TCP_NODELAY */
mysqlnd_set_sock_no_delay(net_stream);
/* TCP -> Set SO_KEEPALIVE */
mysqlnd_set_sock_keepalive(net_stream);
}
@@ -407,25 +407,25 @@ MYSQLND_METHOD(mysqlnd_vio, set_client_option)(MYSQLND_VIO * const net, enum_mys
break;
default:
DBG_INF("default = MYSQLND_SSL_PEER_DEFAULT_ACTION");
val = MYSQLND_SSL_PEER_DEFAULT;
break;
}
net->data->options.ssl_verify_peer = val;
break;
}
case MYSQL_OPT_READ_TIMEOUT:
- net->data->options.timeout_read = *(unsigned int*) value;
+ net->data->options.timeout_read = *(double*) value;
break;
#ifdef WHEN_SUPPORTED_BY_MYSQLI
case MYSQL_OPT_WRITE_TIMEOUT:
- net->data->options.timeout_write = *(unsigned int*) value;
+ net->data->options.timeout_write = *(double*) value;
break;
#endif
default:
DBG_RETURN(FAIL);
}
DBG_RETURN(PASS);
}
/* }}} */
@@ -569,23 +569,23 @@ MYSQLND_METHOD(mysqlnd_vio, enable_ssl)(MYSQLND_VIO * const net)
get rid of the context. we are persistent and if this is a real pconn used by mysql/mysqli,
then the context would not survive cleaning of EG(regular_list), where it is registered, as a
resource. What happens is that after this destruction any use of the network will mean usage
of the context, which means usage of already freed memory, bad. Actually we don't need this
context anymore after we have enabled SSL on the connection. Thus it is very simple, we remove it.
*/
php_stream_context_set(net_stream, NULL);
if (net->data->options.timeout_read) {
struct timeval tv;
- DBG_INF_FMT("setting %u as PHP_STREAM_OPTION_READ_TIMEOUT", net->data->options.timeout_read);
- tv.tv_sec = net->data->options.timeout_read;
- tv.tv_usec = 0;
+ DBG_INF_FMT("setting %f as PHP_STREAM_OPTION_READ_TIMEOUT", net->data->options.timeout_read);
+ tv.tv_sec = (int)net->data->options.timeout_read;
+ tv.tv_usec = (int)(net->data->options.timeout_read * 1000000.0) % 1000000;
php_stream_set_option(net_stream, PHP_STREAM_OPTION_READ_TIMEOUT, 0, &tv);
}
DBG_RETURN(PASS);
#else
DBG_ENTER("mysqlnd_vio::enable_ssl");
DBG_INF("MYSQLND_SSL_SUPPORTED is not defined");
DBG_RETURN(PASS);
#endif
}
@@ -663,27 +663,28 @@ MYSQLND_METHOD(mysqlnd_vio, close_stream)(MYSQLND_VIO * const net, MYSQLND_STATS
DBG_VOID_RETURN;
}
/* }}} */
/* {{{ mysqlnd_vio::init */
static enum_func_status
MYSQLND_METHOD(mysqlnd_vio, init)(MYSQLND_VIO * const net, MYSQLND_STATS * const stats, MYSQLND_ERROR_INFO * const error_info)
{
unsigned int buf_size;
+ double timeout;
DBG_ENTER("mysqlnd_vio::init");
buf_size = MYSQLND_G(net_read_buffer_size); /* this is long, cast to unsigned int*/
net->data->m.set_client_option(net, MYSQLND_OPT_NET_READ_BUFFER_SIZE, (char *)&buf_size);
- buf_size = MYSQLND_G(net_read_timeout); /* this is long, cast to unsigned int*/
- net->data->m.set_client_option(net, MYSQL_OPT_READ_TIMEOUT, (char *)&buf_size);
+ timeout = MYSQLND_G(net_read_timeout); /* this is a double */
+ net->data->m.set_client_option(net, MYSQL_OPT_READ_TIMEOUT, (char *)&timeout);
DBG_RETURN(PASS);
}
/* }}} */
/* {{{ mysqlnd_vio::dtor */
static void
MYSQLND_METHOD(mysqlnd_vio, dtor)(MYSQLND_VIO * const vio, MYSQLND_STATS * const stats, MYSQLND_ERROR_INFO * const error_info)
{
diff --git a/ext/mysqlnd/php_mysqlnd.c b/ext/mysqlnd/php_mysqlnd.c
index 53a85701d1..bea1ec1663 100644
--- a/ext/mysqlnd/php_mysqlnd.c
+++ b/ext/mysqlnd/php_mysqlnd.c
@@ -132,21 +132,21 @@ PHP_MINFO_FUNCTION(mysqlnd)
php_info_print_table_row(2, "extended SSL",
#ifdef MYSQLND_HAVE_SSL
"supported");
#else
"not supported");
#endif
snprintf(buf, sizeof(buf), ZEND_LONG_FMT, MYSQLND_G(net_cmd_buffer_size));
php_info_print_table_row(2, "Command buffer size", buf);
snprintf(buf, sizeof(buf), ZEND_LONG_FMT, MYSQLND_G(net_read_buffer_size));
php_info_print_table_row(2, "Read buffer size", buf);
- snprintf(buf, sizeof(buf), ZEND_LONG_FMT, MYSQLND_G(net_read_timeout));
+ snprintf(buf, sizeof(buf), "%f", MYSQLND_G(net_read_timeout));
php_info_print_table_row(2, "Read timeout", buf);
php_info_print_table_row(2, "Collecting statistics", MYSQLND_G(collect_statistics)? "Yes":"No");
php_info_print_table_row(2, "Collecting memory statistics", MYSQLND_G(collect_memory_statistics)? "Yes":"No");
php_info_print_table_row(2, "Tracing", MYSQLND_G(debug)? MYSQLND_G(debug):"n/a");
/* loaded plugins */
{
smart_str tmp_str = {0};
mysqlnd_plugin_apply_with_argument(mysqlnd_minfo_dump_loaded_plugins, &tmp_str);
@@ -180,21 +180,21 @@ static PHP_GINIT_FUNCTION(mysqlnd)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
mysqlnd_globals->collect_statistics = TRUE;
mysqlnd_globals->collect_memory_statistics = FALSE;
mysqlnd_globals->debug = NULL; /* The actual string */
mysqlnd_globals->dbg = NULL; /* The DBG object*/
mysqlnd_globals->trace_alloc_settings = NULL;
mysqlnd_globals->trace_alloc = NULL;
mysqlnd_globals->net_cmd_buffer_size = MYSQLND_NET_CMD_BUFFER_MIN_SIZE;
mysqlnd_globals->net_read_buffer_size = 32768;
- mysqlnd_globals->net_read_timeout = 31536000;
+ mysqlnd_globals->net_read_timeout = 31536000.0;
mysqlnd_globals->log_mask = 0;
mysqlnd_globals->mempool_default_size = 16000;
mysqlnd_globals->debug_emalloc_fail_threshold = -1;
mysqlnd_globals->debug_ecalloc_fail_threshold = -1;
mysqlnd_globals->debug_erealloc_fail_threshold = -1;
mysqlnd_globals->debug_malloc_fail_threshold = -1;
mysqlnd_globals->debug_calloc_fail_threshold = -1;
mysqlnd_globals->debug_realloc_fail_threshold = -1;
mysqlnd_globals->sha256_server_public_key = NULL;
mysqlnd_globals->fetch_data_copy = FALSE;
@@ -221,21 +221,21 @@ static PHP_INI_MH(OnUpdateNetCmdBufferSize)
/* {{{ PHP_INI_BEGIN
*/
PHP_INI_BEGIN()
STD_PHP_INI_BOOLEAN("mysqlnd.collect_statistics", "1", PHP_INI_ALL, OnUpdateBool, collect_statistics, zend_mysqlnd_globals, mysqlnd_globals)
STD_PHP_INI_BOOLEAN("mysqlnd.collect_memory_statistics","0",PHP_INI_SYSTEM, OnUpdateBool, collect_memory_statistics, zend_mysqlnd_globals, mysqlnd_globals)
STD_PHP_INI_ENTRY("mysqlnd.debug", NULL, PHP_INI_SYSTEM, OnUpdateString, debug, zend_mysqlnd_globals, mysqlnd_globals)
STD_PHP_INI_ENTRY("mysqlnd.trace_alloc", NULL, PHP_INI_SYSTEM, OnUpdateString, trace_alloc_settings, zend_mysqlnd_globals, mysqlnd_globals)
STD_PHP_INI_ENTRY("mysqlnd.net_cmd_buffer_size", MYSQLND_NET_CMD_BUFFER_MIN_SIZE_STR, PHP_INI_ALL, OnUpdateNetCmdBufferSize, net_cmd_buffer_size, zend_mysqlnd_globals, mysqlnd_globals)
STD_PHP_INI_ENTRY("mysqlnd.net_read_buffer_size", "32768",PHP_INI_ALL, OnUpdateLong, net_read_buffer_size, zend_mysqlnd_globals, mysqlnd_globals)
- STD_PHP_INI_ENTRY("mysqlnd.net_read_timeout", "86400",PHP_INI_ALL, OnUpdateLong, net_read_timeout, zend_mysqlnd_globals, mysqlnd_globals)
+ STD_PHP_INI_ENTRY("mysqlnd.net_read_timeout", "86400",PHP_INI_ALL, OnUpdateReal, net_read_timeout, zend_mysqlnd_globals, mysqlnd_globals)
STD_PHP_INI_ENTRY("mysqlnd.log_mask", "0", PHP_INI_ALL, OnUpdateLong, log_mask, zend_mysqlnd_globals, mysqlnd_globals)
STD_PHP_INI_ENTRY("mysqlnd.mempool_default_size","16000", PHP_INI_ALL, OnUpdateLong, mempool_default_size, zend_mysqlnd_globals, mysqlnd_globals)
STD_PHP_INI_ENTRY("mysqlnd.sha256_server_public_key",NULL, PHP_INI_PERDIR, OnUpdateString, sha256_server_public_key, zend_mysqlnd_globals, mysqlnd_globals)
STD_PHP_INI_BOOLEAN("mysqlnd.fetch_data_copy", "0", PHP_INI_ALL, OnUpdateBool, fetch_data_copy, zend_mysqlnd_globals, mysqlnd_globals)
#if PHP_DEBUG
STD_PHP_INI_ENTRY("mysqlnd.debug_emalloc_fail_threshold","-1", PHP_INI_SYSTEM, OnUpdateLong, debug_emalloc_fail_threshold, zend_mysqlnd_globals, mysqlnd_globals)
STD_PHP_INI_ENTRY("mysqlnd.debug_ecalloc_fail_threshold","-1", PHP_INI_SYSTEM, OnUpdateLong, debug_ecalloc_fail_threshold, zend_mysqlnd_globals, mysqlnd_globals)
STD_PHP_INI_ENTRY("mysqlnd.debug_erealloc_fail_threshold","-1", PHP_INI_SYSTEM, OnUpdateLong, debug_erealloc_fail_threshold, zend_mysqlnd_globals, mysqlnd_globals)
STD_PHP_INI_ENTRY("mysqlnd.debug_malloc_fail_threshold","-1", PHP_INI_SYSTEM, OnUpdateLong, debug_malloc_fail_threshold, zend_mysqlnd_globals, mysqlnd_globals)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment