[wp-trac] [WordPress Trac] #27240: Add allow_bail Argument for wpdb->check_connection() the Same as for db_connect()

WordPress Trac noreply at wordpress.org
Fri Feb 28 18:03:24 UTC 2014


#27240: Add allow_bail Argument for wpdb->check_connection() the Same as for
db_connect()
-------------------------+-----------------------------
 Reporter:  DrProtocols  |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Database     |    Version:  trunk
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 The new wpdb check_connection() function is a great addition and
 potentially allows plugins to change to using that function rather than
 having to use their own (especially good now that there is at the
 mysql/mysqli thing to be considered).

 However, as it bails by default (unless the template_redirect action has
 been done) this causes a problem for plugins that handle the broken and
 cannot reconnect failure themselves.

 The db_connect() function has an allow_bail argument that allows the
 caller to prevent the bail action and simply have db_connect() return
 false if a connection failure occurs.

 Adding the same argument and functionality to check_connection()
 (defaulting to true as it does for db_connect()) would allow the caller to
 to have check_connection() return false on a failure and allow the caller
 to handle the failure.

 This would provide a behavioural consistency between the two functions as
 in effect they are both trying to connect to the database.

 The call to db_connect() from within check_connection() would still call
 with false regardless of the value that check_connection() was called
 with.

 (I don't believe that the template_redirect action can be guaranteed to
 have been "done" under every possible scenario where a plugin might want
 to check a database connection which is why I believe the additional
 argument and associated logic is required. For example, would
 template_redirect have been called if a background (cron) task were being
 executed? This condition seems too uncertain to be relied upon).

 Regards

--
Ticket URL: <https://core.trac.wordpress.org/ticket/27240>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list