Skip to content

Feature request #78555. Add the option to disable dblink cleanup #4712

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

Closed
wants to merge 2 commits into from
Closed
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
10 changes: 6 additions & 4 deletions ext/mysqli/mysqli.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,13 @@ static void mysqli_link_free_storage(zend_object *object)

if (my_res && my_res->ptr) {
MY_MYSQL *mysql = (MY_MYSQL *)my_res->ptr;
if (mysql->mysql) {
php_mysqli_close(mysql, MYSQLI_CLOSE_EXPLICIT, my_res->status);
if(!mysql->disable_cleanup) {
if (mysql->mysql) {
php_mysqli_close(mysql, MYSQLI_CLOSE_EXPLICIT, my_res->status);
}
php_clear_mysql(mysql);
efree(mysql);
}
php_clear_mysql(mysql);
efree(mysql);
my_res->status = MYSQLI_STATUS_UNKNOWN;
}
mysqli_objects_free_storage(object);
Expand Down
20 changes: 20 additions & 0 deletions ext/mysqli/mysqli_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,25 @@ PHP_FUNCTION(mysqli_debug)
}
/* }}} */

/* {{{ proto void mysqli_disable_cleanup(object link, bool value)
Turn link cleanup on or off when the object is destroyed
*/
PHP_FUNCTION(mysqli_disable_cleanup)
{
MY_MYSQL *mysql;
zval *mysql_link;
zend_bool value;

if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ob", &mysql_link, mysqli_link_class_entry, &value) == FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
mysql->disable_cleanup = value;
RETURN_TRUE;
}
/* }}} */


/* {{{ proto bool mysqli_dump_debug_info(object link)
*/
PHP_FUNCTION(mysqli_dump_debug_info)
Expand Down Expand Up @@ -1510,6 +1529,7 @@ void php_mysqli_init(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_method)
mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
mysqli_resource->ptr = (void *)mysql;
mysqli_resource->status = MYSQLI_STATUS_INITIALIZED;
mysql->disable_cleanup = FALSE;

if (!is_method) {
MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_link_class_entry);
Expand Down
8 changes: 7 additions & 1 deletion ext/mysqli/mysqli_fe.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_mysqli_debug, 0, 0, 1)
ZEND_ARG_INFO(0, debug_options)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_mysqli_disable_cleanup, 0, 0, 2)
MYSQLI_ZEND_ARG_OBJ_INFO_LINK()
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_mysqli_result_and_fieldnr, 0, 0, 2)
MYSQLI_ZEND_ARG_OBJ_INFO_RESULT()
ZEND_ARG_INFO(0, field_nr)
Expand Down Expand Up @@ -401,7 +406,6 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_mysqli_no_options, 0, 0, 0)
ZEND_END_ARG_INFO()


/* {{{ mysqli_functions[]
*
* Every user visible function must have an entry in mysqli_functions[].
Expand All @@ -420,6 +424,7 @@ const zend_function_entry mysqli_functions[] = {
PHP_FE(mysqli_data_seek, arginfo_mysqli_data_seek)
PHP_FE(mysqli_dump_debug_info, arginfo_mysqli_only_link)
PHP_FE(mysqli_debug, arginfo_mysqli_debug)
PHP_FE(mysqli_disable_cleanup, arginfo_mysqli_disable_cleanup)
PHP_FE(mysqli_errno, arginfo_mysqli_only_link)
PHP_FE(mysqli_error, arginfo_mysqli_only_link)
PHP_FE(mysqli_error_list, arginfo_mysqli_only_link)
Expand Down Expand Up @@ -549,6 +554,7 @@ const zend_function_entry mysqli_link_methods[] = {
PHP_FALIAS(connect, mysqli_connect, arginfo_mysqli_connect)
PHP_FALIAS(dump_debug_info, mysqli_dump_debug_info, arginfo_mysqli_no_params)
PHP_FALIAS(debug, mysqli_debug, arginfo_mysqli_debug)
PHP_FALIAS(disable_cleanup, mysqli_disable_cleanup, arginfo_mysqli_disable_cleanup)
#ifdef HAVE_MYSQLI_GET_CHARSET
PHP_FALIAS(get_charset, mysqli_get_charset, arginfo_mysqli_no_params)
#endif
Expand Down
1 change: 1 addition & 0 deletions ext/mysqli/mysqli_fe.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ PHP_FUNCTION(mysqli_connect_errno);
PHP_FUNCTION(mysqli_connect_error);
PHP_FUNCTION(mysqli_data_seek);
PHP_FUNCTION(mysqli_debug);
PHP_FUNCTION(mysqli_disable_cleanup);
PHP_FUNCTION(mysqli_dump_debug_info);
PHP_FUNCTION(mysqli_errno);
PHP_FUNCTION(mysqli_error);
Expand Down
1 change: 1 addition & 0 deletions ext/mysqli/php_mysqli_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ typedef struct {
php_stream *li_stream;
unsigned int multi_query;
zend_bool persistent;
zend_bool disable_cleanup; /* Disable dtor cleanup */
#if defined(MYSQLI_USE_MYSQLND)
int async_result_fetch_type;
#endif
Expand Down
1 change: 1 addition & 0 deletions ext/mysqli/tests/mysqli_class_mysqli_interface.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ require_once('skipifconnectfailure.inc');
'commit' => true,
'connect' => true,
'dump_debug_info' => true,
'disable_cleanup' => true,
'escape_string' => true,
'get_charset' => true,
'get_client_info' => true,
Expand Down
30 changes: 30 additions & 0 deletions ext/mysqli/tests/mysqli_class_mysqli_reflection.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,36 @@ isPassedByReference: no
isOptional: no
isDefaultValueAvailable: no

Inspecting method 'disable_cleanup'
isFinal: no
isAbstract: no
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isConstructor: no
isDestructor: no
isInternal: yes
isUserDefined: no
returnsReference: no
Modifiers: 1
Number of Parameters: 2
Number of Required Parameters: 2

Inspecting parameter 'link' of method 'disable_cleanup'
isArray: no
allowsNull: no
isPassedByReference: no
isOptional: no
isDefaultValueAvailable: no

Inspecting parameter 'value' of method 'disable_cleanup'
isArray: no
allowsNull: no
isPassedByReference: no
isOptional: no
isDefaultValueAvailable: no

Inspecting method 'dump_debug_info'
isFinal: no
isAbstract: no
Expand Down