adjust design, add preferrred and enforce redirect when on, and new test cases

This commit is contained in:
Qianqian Bu 2020-02-11 17:42:45 +08:00
Родитель fda5fbe2bc
Коммит 9476f820a9
19 изменённых файлов: 597 добавлений и 151 удалений

Просмотреть файл

@ -9,7 +9,23 @@ connection, and use the new one afterward.
+---------------------------+ +---------------------------+
OPTION DESCRIPTION OPTION DESCRIPTION
------------------ ---------------------------------------------------------- ------------------ ----------------------------------------------------------
mysqlnd_azure.enabled This option is to control enable or disable mysqlnd_rd. mysqlnd_azure.enableRedirect This option is to control enable or disable redirection feature of mysqlnd_azure.
If this is set to 0, it will not use redirection. If this is set to off, it will not use redirection.
(Default: 0)
Available option values:
(Default: off)
---------------|------------------------------------------------------------------------------------------------------------------------------------------
off(0) | - It will not use redirection.
---------------|------------------------------------------------------------------------------------------------------------------------------------------
on(1) | - If ssl is off, no connection will be made, return error:
| "mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL."
| - If on server side redirection is not available, abort the first connection and return error:
| "Connection aborted because redirection is not enabled on the MySQL server or the network package doesn't meet meet redirection protocol."
| - If server supports redirection, but the redirected connection failed for any reason, also abort the first proxy connection.
| Return the error of the redirected connection.
---------------|------------------------------------------------------------------------------------------------------------------------------------------
preferred(2) | - it will use redirection if possible.
| - If connection does not use SSL, or server does not support redirection, or redirected connection fails
| to connect for any non-fatal reason while the proxy connection is still a valid one, it will fallback
| to the first proxy connection.
---------------|------------------------------------------------------------------------------------------------------------------------------------------

Просмотреть файл

@ -3,6 +3,52 @@ The source code here is a PHP extension implemented using mysqlnd plugin API (ht
**Important notice: There is a limitation that for Azure MySQL, redirection is only possible when the connection is configured with SSL, and it will only support TLS 1.2 with FIPS approved cipher for redirection.** **Important notice: There is a limitation that for Azure MySQL, redirection is only possible when the connection is configured with SSL, and it will only support TLS 1.2 with FIPS approved cipher for redirection.**
## Option Usage
In 1.0.x versions, the option is with name **mysqlnd_azure.enabled**. When redirection is turned on, but connection does not use SSL,
or server does not support redirection, or redirected connection fails to connect for any non-fatal reason while the proxy connection
is still a valid one, it will fallback to the first proxy connection. The detailed usage of the option enableRedirect is as follows:
(Version 1.0.x. Config name: **mysqlnd_azure.enabled**. Valid value: on/off. Default value: off)
<table>
<tr>
<td>off(0)</td>
<td> - It will not use redirection. </td>
</tr>
<tr>
<td>on(1)</td>
<td> - It will use redirection if possible (Connection is with SSL and Server supports/need redirection).</br>
- If connection does not use SSL, or server does not support redirection, or redirected connection fails to connect for any non-fatal reason while the proxy connection is still a valid one, it will fallback to the first proxy connection.
</td>
</tr>
</table>
Since 1.1.0RC1, the logic changes as follows:
- The option mysqlnd_azure.enabled is renamed to **mysqlnd_azure.enableRedirect**, and there is a new option value "preferred" provided.
- The detailed usage of the option enableRedirect is as follows:
(Version 1.1.0RC1. Config name: **mysqlnd_azure.enableRedirect**. Valid value: on/off/preferred. Default value: off)
<table>
<tr>
<td>off(0)</td>
<td> - It will not use redirection. </td>
</tr>
<tr>
<td>on(1)</td>
<td> - If SSL is off, no connection will be made, return error:
<i>"mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL."</i></br>
- If on server side redirection is not supported, abort the first connection and return error: <i>"Connection aborted because redirection is not enabled on the MySQL server or the network package doesn't meet meet redirection protocol."</i></br>
- If server supports redirection, but the redirected connection failed for any reason, also abort the first proxy connection. Return the error of the redirected connection.
</td>
</tr>
<tr>
<td>
preferred(2)
</td>
<td> - It will use redirection if possible.</br>
- If connection does not use SSL, or server does not support redirection, or redirected connection fails to connect for any non-fatal reason while the proxy connection is still a valid one, it will fallback to the first proxy connection.
</td>
</tr>
</table>
## Name and Extension Version ## Name and Extension Version
Extension name: **mysqlnd_azure** Extension name: **mysqlnd_azure**
@ -15,6 +61,12 @@ Valid version:
- 1.0.3RC Change: fix the crash problem when working with PDO interface with flag PDO::ATTR_PERSISTENT=>false. - 1.0.3RC Change: fix the crash problem when working with PDO interface with flag PDO::ATTR_PERSISTENT=>false.
This version is marked as beta, so please use *pecl install mysqlnd_azure-1.0.3RC* to install when using pecl. This version is marked as beta, so please use *pecl install mysqlnd_azure-1.0.3RC* to install when using pecl.
- 1.0.3 Change: Remove the use of is_using_redirect flag. More strict validation and new test cases with php built-in web server. - 1.0.3 Change: Remove the use of is_using_redirect flag. More strict validation and new test cases with php built-in web server.
- 1.1.0RC1 Change:
1. Rename option mysqlnd_azure.enabled to mysqlnd_azure.enableRedirect, and add a new option value "preferred".
2. When enableRedirect is "preferred", it will use redirection if possible. If connection does not use SSL, or server does not support redirection, or redirected connection fails to connect for any non-fatal reason while the proxy connection is still a valid one, it will fallback to the first proxy connection.
3. When enableRedirect is "on", SSL is off, no connection will be made, return error "mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL."
4. When enableRedirect is "on", but on server side redirection is not supported, abort the first connection and return error "Connection aborted because redirection is not enabled on the MySQL server or the network package doesn't meet meet redirection protocol."
5. When enableRedirect is "on" and server supports redirection, but the redirected connection failed for any reason, also abort the first proxy connection. Return the error of the redirected connection.
Following is a brief guide of how to install using pecl or build and test the extension from source. Following is a brief guide of how to install using pecl or build and test the extension from source.
@ -93,7 +145,8 @@ Then you can run **make install** to put the .so to your php so library. However
- put mysqlnd_azure.so under extension_dir. - put mysqlnd_azure.so under extension_dir.
- under directory for additional .ini files, you will find the ini files for the common used modules, e.g. 10-mysqlnd.ini for mysqlnd, 20-mysqli.ini for mysqli. Create a new ini file for mysqlnd_azure here. **Make sure the alphabet order of the name is after that of mysqnld**, since the modules are loaded according to the name order of the ini files. E.g. if mysqlnd ini is with name 10-mysqlnd.ini,then name the ini as 20-mysqlnd-azure.ini. In the ini file, add the following two lines: - under directory for additional .ini files, you will find the ini files for the common used modules, e.g. 10-mysqlnd.ini for mysqlnd, 20-mysqli.ini for mysqli. Create a new ini file for mysqlnd_azure here. **Make sure the alphabet order of the name is after that of mysqnld**, since the modules are loaded according to the name order of the ini files. E.g. if mysqlnd ini is with name 10-mysqlnd.ini,then name the ini as 20-mysqlnd-azure.ini. In the ini file, add the following two lines:
- extension=mysqlnd_azure - extension=mysqlnd_azure
- mysqlnd_azure.enabled = on ; you can also set this to off to disable redirection - mysqlnd_azure.enableRedirect = on/off/preferred
- **Notice:** since 1.1.0RC1, if this value is set to on, the connection must be configured with SSL, and it requires server support redirection. Otherwise, the connection will fail. Please check the Option Usage section for detailed information.
## Step to build on Windows ## Step to build on Windows
@ -139,15 +192,17 @@ After this, the code directory should look like C:\php-sdk\phpdev\vc15\x64\php-s
- extension=mysqlnd_azure - extension=mysqlnd_azure
- Under the Module Settings section add: - Under the Module Settings section add:
- [mysqlnd_azure] - [mysqlnd_azure]
- mysqlnd_azure.enabled = on - mysqlnd_azure.enableRedirect = on/off/preferred
- **Notice:** since 1.1.0RC1, if this value is set to on, the connection must be configured with SSL, and it requires server support redirection. Otherwise, the connection will fail. Please check the Option Usage section for detailed information.
## Test ## Test
* Currently redirection is only possible when the connection is via ssl, and it need that the redirection feature switch is enabled on server side. Following is a snippet to test connection with redirection: * Currently redirection is only possible when the connection is via ssl, and it need that the redirection feature switch is enabled on server side. Following is a snippet to test connection with redirection:
```php ```php
echo "mysqlnd_azure.enabled: ", ini_get("mysqlnd_azure.enabled") == true?"On":"Off", "\n"; echo "mysqlnd_azure.enableRedirect: ", ini_get("mysqlnd_azure.enableRedirect"), "\n";
$db = mysqli_init(); $db = mysqli_init();
//The connection must be configured with SSL for redirection test
$link = mysqli_real_connect ($db, 'your-hostname-with-redirection-enabled', 'user@host', 'password', "db", 3306, NULL, MYSQLI_CLIENT_SSL); $link = mysqli_real_connect ($db, 'your-hostname-with-redirection-enabled', 'user@host', 'password', "db", 3306, NULL, MYSQLI_CLIENT_SSL);
if (!$link) { if (!$link) {
die ('Connect error (' . mysqli_connect_errno() . '): ' . mysqli_connect_error() . "\n"); die ('Connect error (' . mysqli_connect_errno() . '): ' . mysqli_connect_error() . "\n");

Просмотреть файл

@ -340,9 +340,16 @@ MYSQLND_METHOD(mysqlnd_azure_data, connect)(MYSQLND_CONN_DATA ** pconn,
unsigned int ui_redirect_port = 0; unsigned int ui_redirect_port = 0;
zend_bool serverSupportRedirect = get_redirect_info(conn, redirect_host, redirect_user, &ui_redirect_port); zend_bool serverSupportRedirect = get_redirect_info(conn, redirect_host, redirect_user, &ui_redirect_port);
if (!serverSupportRedirect) { if (!serverSupportRedirect) {
//do nothing else for redirection, just use the previous connection DBG_ENTER("[redirect]: Server doesnot supoort redirection.");
DBG_ENTER("[redirect]: Server doesnot supoort redirection, do not need redirection. "); if(MYSQLND_AZURE_G(enableRedirect) == REDIRECT_ON) {
goto after_conn; //REDIRECT_ON, if redirection is not supported, abort the original connection and return error
conn->m->send_close(conn);
SET_CLIENT_ERROR(conn->error_info, MYSQLND_AZURE_ENFORCE_REDIRECT_ERROR_NO, UNKNOWN_SQLSTATE, "Connection aborted because redirection is not enabled on the MySQL server or the network package doesn't meet meet redirection protocol.");
goto err;
} else {
//REDIRECT_PREFERRED, do nothing else for redirection, just use the previous connection
goto after_conn;
}
} }
//Get here means serverSupportRedirect //Get here means serverSupportRedirect
@ -359,9 +366,18 @@ MYSQLND_METHOD(mysqlnd_azure_data, connect)(MYSQLND_CONN_DATA ** pconn,
enum_func_status ret = FAIL; enum_func_status ret = FAIL;
MYSQLND* redirect_conneHandle = mysqlnd_init(MYSQLND_CLIENT_KNOWS_RSET_COPY_DATA, conn->persistent); //init MYSQLND but only need only MYSQLND_CONN_DATA here MYSQLND* redirect_conneHandle = mysqlnd_init(MYSQLND_CLIENT_KNOWS_RSET_COPY_DATA, conn->persistent); //init MYSQLND but only need only MYSQLND_CONN_DATA here
if(!redirect_conneHandle) { if(!redirect_conneHandle) {
//redirect_conneHandle init failed, do nothing more, just use the original connection DBG_ENTER("[redirect]: init redirect_conneHandle failed");
goto after_conn; if(MYSQLND_AZURE_G(enableRedirect) == REDIRECT_ON) {
//REDIRECT_ON, abort the original connection and return error
conn->m->send_close(conn);
SET_CLIENT_ERROR(conn->error_info, MYSQLND_AZURE_ENFORCE_REDIRECT_ERROR_NO, UNKNOWN_SQLSTATE, "Connection aborted because init redirection failed.");
goto err;
} else {
//REDIRECT_PREFERRED, do nothing else for redirection, just use the previous connection
goto after_conn;
}
} }
MYSQLND_CONN_DATA* redirect_conn = redirect_conneHandle->data; MYSQLND_CONN_DATA* redirect_conn = redirect_conneHandle->data;
redirect_conneHandle->data = NULL; redirect_conneHandle->data = NULL;
mnd_pefree(redirect_conneHandle, redirect_conneHandle->persistent); mnd_pefree(redirect_conneHandle, redirect_conneHandle->persistent);
@ -371,13 +387,22 @@ MYSQLND_METHOD(mysqlnd_azure_data, connect)(MYSQLND_CONN_DATA ** pconn,
//init redirect_conn options failed, just use the proxy connection //init redirect_conn options failed, just use the proxy connection
if (ret == FAIL) { if (ret == FAIL) {
//release resource DBG_ENTER("[redirect]: init redirection option failed. ");
redirect_conn->m->dtor(redirect_conn); redirect_conn->m->dtor(redirect_conn); //release created resource
goto after_conn;
if(MYSQLND_AZURE_G(enableRedirect) == REDIRECT_ON) {
//REDIRECT_ON, abort the original connection
conn->m->send_close(conn);
SET_CLIENT_ERROR(conn->error_info, MYSQLND_AZURE_ENFORCE_REDIRECT_ERROR_NO, UNKNOWN_SQLSTATE, "Connection aborted because init redirection failed.");
goto err;
} else {
//REDIRECT_PREFERRED, do nothing else for redirection, just use the previous connection
goto after_conn;
}
} }
//init redirect_conn succeeded, use this conn to start a new connection and handshake //init redirect_conn succeeded, use this conn to start a new connection and handshake
const MYSQLND_CSTRING redirect_hostname = { redirect_host, strlen(redirect_host) }; const MYSQLND_CSTRING redirect_hostname = { redirect_host, strlen(redirect_host) };
const MYSQLND_CSTRING redirect_username = { redirect_user, strlen(redirect_user) }; const MYSQLND_CSTRING redirect_username = { redirect_user, strlen(redirect_user) };
MYSQLND_STRING redirect_transport = redirect_conn->m->get_scheme(redirect_conn, redirect_hostname, &socket_or_pipe, ui_redirect_port, &unix_socket, &named_pipe); MYSQLND_STRING redirect_transport = redirect_conn->m->get_scheme(redirect_conn, redirect_hostname, &socket_or_pipe, ui_redirect_port, &unix_socket, &named_pipe);
@ -387,6 +412,7 @@ MYSQLND_METHOD(mysqlnd_azure_data, connect)(MYSQLND_CONN_DATA ** pconn,
enum_func_status redirectState = redirect_conn->m->connect_handshake(redirect_conn, &redirect_scheme, &redirect_username, &password, &database, mysql_flags); enum_func_status redirectState = redirect_conn->m->connect_handshake(redirect_conn, &redirect_scheme, &redirect_username, &password, &database, mysql_flags);
if (redirectState == PASS) { //handshake with redirect_conn succeeded, replace original connection info with redirect_conn and add the redirect info into cache table if (redirectState == PASS) { //handshake with redirect_conn succeeded, replace original connection info with redirect_conn and add the redirect info into cache table
DBG_ENTER("[redirect]: mysql redirect handshake succeeded.");
//add the redirect info into cache table //add the redirect info into cache table
mysqlnd_azure_add_redirect_cache(username.s, hostname.s, port, redirect_username.s, redirect_hostname.s, ui_redirect_port); mysqlnd_azure_add_redirect_cache(username.s, hostname.s, port, redirect_username.s, redirect_hostname.s, ui_redirect_port);
@ -410,19 +436,32 @@ MYSQLND_METHOD(mysqlnd_azure_data, connect)(MYSQLND_CONN_DATA ** pconn,
port = ui_redirect_port; port = ui_redirect_port;
transport = redirect_transport; transport = redirect_transport;
DBG_ENTER("[redirect]: mysql redirect handshake succeeded."); } else { //redirect failed. if REDIRECT_ON, also abort the original conn, if REDIRECT_PREFERRED, use original connection
DBG_ENTER("[redirect]: mysql redirect handshake fails");
} if (MYSQLND_AZURE_G(enableRedirect) == REDIRECT_PREFERRED) {
else { //redirect failed. use original connection information //free resource and use original connection
redirect_conn->m->dtor(redirect_conn);
if (redirect_transport.s) {
mnd_sprintf_free(redirect_transport.s);
redirect_transport.s = NULL;
}
goto after_conn;
//free resource, and use original connection information } else { //REDIRECT_ON, free original connect, and use redirect_conn to handle error
redirect_conn->m->dtor(redirect_conn); conn->m->send_close(conn);
if (redirect_transport.s) { conn->m->dtor(conn);
mnd_sprintf_free(redirect_transport.s); pfc = NULL;
redirect_transport.s = NULL; if (transport.s) {
mnd_sprintf_free(transport.s);
transport.s = NULL;
}
conn = redirect_conn;
*pconn = redirect_conn;
pfc = redirect_conn->protocol_frame_codec;
goto err;
} }
DBG_ENTER("[redirect]: mysql redirect handshake fails, use original connection information!");
} }
} }
@ -582,7 +621,7 @@ MYSQLND_METHOD(mysqlnd_azure, connect)(MYSQLND * conn_handle,
mysqlnd_options4(conn_handle, MYSQL_OPT_CONNECT_ATTR_ADD, "_server_host", hostname.s); mysqlnd_options4(conn_handle, MYSQL_OPT_CONNECT_ATTR_ADD, "_server_host", hostname.s);
} }
if (!MYSQLND_AZURE_G(enabled)) { if (MYSQLND_AZURE_G(enableRedirect) == REDIRECT_OFF) {
DBG_ENTER("mysqlnd_azure::connect redirect disabled"); DBG_ENTER("mysqlnd_azure::connect redirect disabled");
ret = org_conn_d_m.connect(*pconn, hostname, username, password, database, port, socket_or_pipe, mysql_flags); ret = org_conn_d_m.connect(*pconn, hostname, username, password, database, port, socket_or_pipe, mysql_flags);
} }
@ -592,7 +631,15 @@ MYSQLND_METHOD(mysqlnd_azure, connect)(MYSQLND * conn_handle,
//Redirection is only possible with SSL at present. Continue with no redirection if SSL is not set //Redirection is only possible with SSL at present. Continue with no redirection if SSL is not set
unsigned int temp_flags = (*pconn)->m->get_updated_connect_flags(*pconn, mysql_flags); unsigned int temp_flags = (*pconn)->m->get_updated_connect_flags(*pconn, mysql_flags);
if (!(temp_flags & CLIENT_SSL)) { if (!(temp_flags & CLIENT_SSL)) {
ret = org_conn_d_m.connect(*pconn, hostname, username, password, database, port, socket_or_pipe, mysql_flags); if((MYSQLND_AZURE_G(enableRedirect) == REDIRECT_ON)) {
SET_CLIENT_ERROR((*pconn)->error_info, MYSQLND_AZURE_ENFORCE_REDIRECT_ERROR_NO, UNKNOWN_SQLSTATE, "mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL.");
(*pconn)->m->local_tx_end(*pconn, this_func, FAIL);
(*pconn)->m->free_contents(*pconn);
return FAIL;
}
else {
ret = org_conn_d_m.connect(*pconn, hostname, username, password, database, port, socket_or_pipe, mysql_flags);
}
} }
else { //SSL is enabled else { //SSL is enabled

Просмотреть файл

@ -36,6 +36,8 @@ typedef struct st_mysqlnd_azure_redirect_info {
#define MAX_REDIRECT_HOST_LEN 128 #define MAX_REDIRECT_HOST_LEN 128
#define MAX_REDIRECT_USER_LEN 128 #define MAX_REDIRECT_USER_LEN 128
#define MYSQLND_AZURE_ENFORCE_REDIRECT_ERROR_NO CR_NOT_IMPLEMENTED
void mysqlnd_azure_minit_register_hooks(); void mysqlnd_azure_minit_register_hooks();
enum_func_status mysqlnd_azure_add_redirect_cache(const char* user, const char* host, int port, const char* redirect_user, const char* redirect_host, int redirect_port); enum_func_status mysqlnd_azure_add_redirect_cache(const char* user, const char* host, int port, const char* redirect_user, const char* redirect_host, int redirect_port);

Просмотреть файл

@ -16,19 +16,24 @@
<email>Qianqian.Bu@microsoft.com</email> <email>Qianqian.Bu@microsoft.com</email>
<active>yes</active> <active>yes</active>
</lead> </lead>
<date>2020-02-10</date> <date>2020-02-15</date>
<time>15:00:13</time> <time>15:00:13</time>
<version> <version>
<release>1.0.3</release> <release>1.1.0RC1</release>
<api>1.0.3</api> <api>1.1.0RC1</api>
</version> </version>
<stability> <stability>
<release>stable</release> <release>beta</release>
<api>stable</api> <api>beta</api>
</stability> </stability>
<license uri="http://www.php.net/license">PHP License</license> <license uri="http://www.php.net/license">PHP License</license>
<notes> <notes>
- Remove the use of is_using_redirect flag. More strict validation and test cases with php built-in web server. - 1. Rename option mysqlnd_azure.enabled to mysqlnd_azure.enableRedirect.
- 2. When enableRedirect is "on", ssl is off, no connection will be made, return error "mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL."
- 3. When enableRedirect is "on", but on server side redirection is not available, abort the first connection and return error "Connection aborted because redirection is not enabled on the MySQL server or the network package doesn't meet meet redirection protocol."
- 4. When enableRedirect is "on" and server supports redirection, but the redirected connection failed for any reason, also abort the first proxy connection. Return the error of the redirected connection.
- 5. A new option for mysqlnd_azure.enableRedirect is introduced with name "preferred". When enableRedirect is "preferred", it will use redirection if possible.
If connection does not use SSL, or server does not support redirection, or redirected connection fails to connect for any non-fatal reason while the proxy connection is still a valid one, it will fallback to the first proxy connection.
</notes> </notes>
<contents> <contents>
<dir name="/"> <dir name="/">
@ -39,8 +44,10 @@
<file md5sum="81379d753b8268922e3e3dd8c11c803c" name="redirect_cache.c" role="src" /> <file md5sum="81379d753b8268922e3e3dd8c11c803c" name="redirect_cache.c" role="src" />
<file md5sum="f6ce2d3ccfaa1d8e53196f9df9043b35" name="mysqlnd_azure.h" role="src" /> <file md5sum="f6ce2d3ccfaa1d8e53196f9df9043b35" name="mysqlnd_azure.h" role="src" />
<file md5sum="207e117afe26f28a75d83776e88d7ee0" name="php_mysqlnd_azure.h" role="src" /> <file md5sum="207e117afe26f28a75d83776e88d7ee0" name="php_mysqlnd_azure.h" role="src" />
<file md5sum="1d60dd2a72d2d9a325e68070b7fd0fbf" name="tests/mysqli_azure_redirection_enabled.phpt" role="test" /> <file md5sum="1d60dd2a72d2d9a325e68070b7fd0fbf" name="tests/mysqli_azure_redirection_on.phpt" role="test" />
<file md5sum="a678a17b08f337292c0471b26be405f5" name="tests/mysqli_azure_redirection_disabled.phpt" role="test" /> <file md5sum="a678a17b08f337292c0471b26be405f5" name="tests/mysqli_azure_redirection_off.phpt" role="test" />
<file md5sum="a678a17b08f337292c0471b26be405f5" name="tests/mysqli_azure_redirection_preferred.phpt" role="test" />
<file md5sum="a678a17b08f337292c0471b26be405f5" name="tests/mysqli_azure_option_test.phpt" role="test" />
<file md5sum="271878ad9afcd0f4304529ff9522e034" name="tests/connect.inc" role="test" /> <file md5sum="271878ad9afcd0f4304529ff9522e034" name="tests/connect.inc" role="test" />
<file md5sum="d621e9a3ad808225480ee11b361338ad" name="tests/skipif.inc" role="test" /> <file md5sum="d621e9a3ad808225480ee11b361338ad" name="tests/skipif.inc" role="test" />
<file md5sum="841204de228db4ea0150bf7289956163" name="tests/skipifconnectfailure.inc" role="test" /> <file md5sum="841204de228db4ea0150bf7289956163" name="tests/skipifconnectfailure.inc" role="test" />
@ -72,6 +79,26 @@
<providesextension>mysqlnd_azure</providesextension> <providesextension>mysqlnd_azure</providesextension>
<extsrcrelease /> <extsrcrelease />
<changelog> <changelog>
<release>
<version>
<release>1.1.0RC1</release>
<api>1.1.0RC1</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<date>2020-02-15</date>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- 1. Rename option mysqlnd_azure.enabled to mysqlnd_azure.enableRedirect, and add a new option value "preferred".
- 2. When enableRedirect is "on", ssl is off, no connection will be made, return error "mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL."
- 3. When enableRedirect is "on", but on server side redirection is not available, abort the first connection and return error "Connection aborted because redirection is not enabled on the MySQL server or the network package doesn't meet meet redirection protocol."
- 4. When enableRedirect is "on" and server supports redirection, but the redirected connection failed for any reason, also abort the first proxy connection. Return the error of the redirected connection.
- 5. A new option for mysqlnd_azure.enableRedirect is introduced with name "preferred". When enableRedirect is "preferred", it will use redirection if possible.
If connection does not use SSL, or server does not support redirection, or redirected connection fails to connect for any non-fatal reason while the proxy connection is still a valid one, it will fallback to the first proxy connection.
</notes>
</release>
<release> <release>
<version> <version>
<release>1.0.3</release> <release>1.0.3</release>

Просмотреть файл

@ -28,13 +28,45 @@
ZEND_DECLARE_MODULE_GLOBALS(mysqlnd_azure) ZEND_DECLARE_MODULE_GLOBALS(mysqlnd_azure)
/* {{{ OnUpdateEnableRedirect */
static ZEND_INI_MH(OnUpdateEnableRedirect)
{
if (STRING_EQUALS(new_value,"preferred")
|| STRING_EQUALS(new_value, "2")) {
MYSQLND_AZURE_G(enableRedirect) = REDIRECT_PREFERRED;
} else if (STRING_EQUALS(new_value, "on")
|| STRING_EQUALS(new_value, "yes")
|| STRING_EQUALS(new_value, "true")
|| STRING_EQUALS(new_value, "1")) {
MYSQLND_AZURE_G(enableRedirect) = REDIRECT_ON;
} else {
MYSQLND_AZURE_G(enableRedirect) = REDIRECT_OFF;
}
return SUCCESS;
}
/* }}} */
/* {{{ PHP_INI */
PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("mysqlnd_azure.enableRedirect", "preferred", PHP_INI_ALL, OnUpdateEnableRedirect, enableRedirect, zend_mysqlnd_azure_globals, mysqlnd_azure_globals)
PHP_INI_END()
/* }}} */
/* {{{ PHP_GINIT_FUNCTION */ /* {{{ PHP_GINIT_FUNCTION */
static PHP_GINIT_FUNCTION(mysqlnd_azure) static PHP_GINIT_FUNCTION(mysqlnd_azure)
{ {
#if defined(COMPILE_DL_MYSQLND_AZURE) && defined(ZTS) #if defined(COMPILE_DL_MYSQLND_AZURE) && defined(ZTS)
ZEND_TSRMLS_CACHE_UPDATE(); ZEND_TSRMLS_CACHE_UPDATE();
#endif #endif
mysqlnd_azure_globals->enabled = 0; mysqlnd_azure_globals->enableRedirect = REDIRECT_PREFERRED;
mysqlnd_azure_globals->redirectCache = NULL; mysqlnd_azure_globals->redirectCache = NULL;
} }
/* }}} */ /* }}} */
@ -50,17 +82,6 @@ static PHP_GSHUTDOWN_FUNCTION(mysqlnd_azure)
} }
/* }}} */ /* }}} */
/* {{{ PHP_INI */
/*
It is handy to allow users to disable any mysqlnd plugin globally - not only for debugging :-)
Because we register our plugin in MINIT changes to mysqlnd_ed.enabled shall be bound to
INI_SYSTEM (and PHP restarts).
*/
PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("mysqlnd_azure.enabled", "0", PHP_INI_ALL, OnUpdateBool, enabled, zend_mysqlnd_azure_globals, mysqlnd_azure_globals)
PHP_INI_END()
/* }}} */
/* {{{ PHP_MINIT_FUNCTION /* {{{ PHP_MINIT_FUNCTION
*/ */
static PHP_MINIT_FUNCTION(mysqlnd_azure) static PHP_MINIT_FUNCTION(mysqlnd_azure)
@ -87,8 +108,8 @@ static PHP_MSHUTDOWN_FUNCTION(mysqlnd_azure)
PHP_MINFO_FUNCTION(mysqlnd_azure) PHP_MINFO_FUNCTION(mysqlnd_azure)
{ {
php_info_print_table_start(); php_info_print_table_start();
php_info_print_table_header(2, "mysqlnd_azure", "enabled"); php_info_print_table_header(2, "mysqlnd_azure", "enableRedirect");
php_info_print_table_row(2, "enabled", MYSQLND_AZURE_G(enabled)? "Yes":"No"); php_info_print_table_row(2, "enableRedirect", MYSQLND_AZURE_G(enableRedirect) == REDIRECT_OFF ? "off" : (MYSQLND_AZURE_G(enableRedirect) == REDIRECT_ON ? "on" : "preferred"));
php_info_print_table_end(); php_info_print_table_end();
} }
/* }}} */ /* }}} */
@ -103,14 +124,14 @@ zend_module_entry mysqlnd_azure_module_entry = {
STANDARD_MODULE_HEADER_EX, STANDARD_MODULE_HEADER_EX,
NULL, NULL,
mysqlnd_azure_deps, mysqlnd_azure_deps,
EXT_MYSQLND_AZURE_NAME, PHP_MYSQLND_AZURE_NAME,
NULL, NULL,
PHP_MINIT(mysqlnd_azure), PHP_MINIT(mysqlnd_azure),
PHP_MSHUTDOWN(mysqlnd_azure), PHP_MSHUTDOWN(mysqlnd_azure),
NULL, NULL,
NULL, NULL,
PHP_MINFO(mysqlnd_azure), PHP_MINFO(mysqlnd_azure),
EXT_MYSQLND_AZURE_VERSION, PHP_MYSQLND_AZURE_VERSION,
PHP_MODULE_GLOBALS(mysqlnd_azure), PHP_MODULE_GLOBALS(mysqlnd_azure),
PHP_GINIT(mysqlnd_azure), PHP_GINIT(mysqlnd_azure),
PHP_GSHUTDOWN(mysqlnd_azure), PHP_GSHUTDOWN(mysqlnd_azure),

Просмотреть файл

@ -28,14 +28,22 @@
extern zend_module_entry mysqlnd_azure_module_entry; extern zend_module_entry mysqlnd_azure_module_entry;
#define phpext_mysqlnd_azure_ptr &mysqlnd_azure_module_entry #define phpext_mysqlnd_azure_ptr &mysqlnd_azure_module_entry
#define EXT_MYSQLND_AZURE_NAME "mysqlnd_azure" #define PHP_MYSQLND_AZURE_NAME "mysqlnd_azure"
#define EXT_MYSQLND_AZURE_VERSION "1.0.3" #define PHP_MYSQLND_AZURE_VERSION "1.1.0RC1"
#define STRING_EQUALS(z_str,str) (ZSTR_LEN((z_str)) == strlen((str)) && strcasecmp((str), ZSTR_VAL((z_str))) == 0)
ZEND_BEGIN_MODULE_GLOBALS(mysqlnd_azure) ZEND_BEGIN_MODULE_GLOBALS(mysqlnd_azure)
zend_bool enabled; zend_bool enableRedirect;
HashTable* redirectCache; HashTable* redirectCache;
ZEND_END_MODULE_GLOBALS(mysqlnd_azure) ZEND_END_MODULE_GLOBALS(mysqlnd_azure)
typedef enum _mysqlnd_azure_redirect_mode {
REDIRECT_OFF = 0, /* completely disabled */
REDIRECT_ON = 1, /* enabled without fallback, block if redirection fail */
REDIRECT_PREFERRED = 2 /* enabled with fallback */
} mysqlnd_azure_redirect_mode;
PHPAPI ZEND_EXTERN_MODULE_GLOBALS(mysqlnd_azure) PHPAPI ZEND_EXTERN_MODULE_GLOBALS(mysqlnd_azure)
#define MYSQLND_AZURE_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(mysqlnd_azure, v) #define MYSQLND_AZURE_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(mysqlnd_azure, v)

Просмотреть файл

@ -0,0 +1,133 @@
--TEST--
Azure redirection option test for mysqlnd_azure.enableRedirect
--SKIPIF--
<?php
require_once('skipif.inc');
?>
--FILE--
<?php
require_once("connect.inc");
function ini_set_test($value) {
global $host, $user, $passwd, $db, $port;
ini_set("mysqlnd_azure.enableRedirect", $value);
echo ini_get("mysqlnd_azure.enableRedirect"), "\n";
$link = mysqli_init();
$ret = @mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, NULL);
if(!$ret)
echo error_get_last()["message"], "\n";
if($ret) {
if(substr($link->host_info, 0, strlen($host)) == $host)
echo "equal\n";
else
echo "not equal\n";
$link->close();
}
$link = mysqli_init();
$ret = @mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL);
$last_message = "";
if($ret)
$last_message = $link->info;
//Server supports redirection
if(strlen($last_message) > 27 && strcmp(substr($last_message, 0, strlen("Location:")), "Location:")==0) {
$config = ini_get("mysqlnd_azure.enableRedirect");
if(substr($link->host_info, 0, strlen($host)) == $host && (strcasecmp($config, "preferred")==0 || strcasecmp($config, "2")==0))
echo "FAIL\n";
else
echo "PASS\n";
}
else if($ret && is_object($link)) {
if(substr($link->host_info, 0, strlen($host)) == $host)
echo "PASS\n";
else
echo "FAIL\n";
}
else if(!$ret) { //Server does not support redirection and redirect on
$lastError = error_get_last()["message"];
if (strpos($lastError, "Connection aborted because redirection is not enabled on the MySQL server or the network package doesn't meet meet redirection protocol.") !== false)
echo "PASS\n";
else
echo "FAIL\n";
}
if($ret) $link->close();
}
ini_set_test("on");
ini_set_test("On");
ini_set_test("yes");
ini_set_test("Yes");
ini_set_test("true");
ini_set_test("True");
ini_set_test("1");
ini_set_test(1);
ini_set_test("preferred");
ini_set_test("Preferred");
ini_set_test("2");
ini_set_test(2);
ini_set_test("off");
ini_set_test("Off");
ini_set_test("0");
ini_set_test(0);
ini_set_test("otherValue");
echo "Done\n";
?>
--EXPECTF--
on
mysqli_real_connect(): (HY000/2054): mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL.
PASS
On
mysqli_real_connect(): (HY000/2054): mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL.
PASS
yes
mysqli_real_connect(): (HY000/2054): mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL.
PASS
Yes
mysqli_real_connect(): (HY000/2054): mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL.
PASS
true
mysqli_real_connect(): (HY000/2054): mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL.
PASS
True
mysqli_real_connect(): (HY000/2054): mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL.
PASS
1
mysqli_real_connect(): (HY000/2054): mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL.
PASS
1
mysqli_real_connect(): (HY000/2054): mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL.
PASS
preferred
equal
PASS
Preferred
equal
PASS
2
equal
PASS
2
equal
PASS
off
equal
PASS
Off
equal
PASS
0
equal
PASS
0
equal
PASS
otherValue
equal
PASS
Done

Просмотреть файл

@ -1,38 +0,0 @@
--TEST--
Azure redirection test for servers with mysqlnd_azure.enabled=0
--INI--
mysqlnd_azure.enabled=0
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifconnectfailure.inc');
?>
--FILE--
<?php
require_once("connect.inc");
if (($tmp = ini_get("mysqlnd_azure.enabled")) != false)
printf("[001] mysqlnd_azure.enabled not set to false, got '%s'\n", $tmp);
$link = mysqli_init();
$ret = mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL);
if (!$ret || !is_object($link))
{
printf("[002] Cannot connect to the server with ssl using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n - [%d] %s",
$host, $user, $db, $port, $socket, mysqli_connect_errno(), mysqli_connect_error());
die();
}
echo $link->host_info."\n";
echo $link->info."\n";
if(substr($link->host_info, 0, strlen($host)) == $host)
echo "1\n";
else
echo "0\n";
mysqli_close($link);
echo "Done\n";
?>
--EXPECTF--
%s
Location: mysql://%s.%s:%d/user=%s@%s
1
Done

Просмотреть файл

@ -1,38 +0,0 @@
--TEST--
Azure redirection test for servers when mysqlnd_azure.enabled
--INI--
mysqlnd_azure.enabled=1
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifconnectfailure.inc');
?>
--FILE--
<?php
require_once("connect.inc");
if (($tmp = ini_get("mysqlnd_azure.enabled")) != true)
printf("[001] mysqlnd_azure.enabled not set to true, got '%s'\n", $tmp);
$link = mysqli_init();
$ret = mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL);
if (!$ret || !is_object($link))
{
printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n - [%d] %s with ssl",
$host, $user, $db, $port, $socket, mysqli_connect_errno(), mysqli_connect_error());
die();
}
echo $link->host_info."\n";
echo $link->info."\n";
if(substr($link->host_info, 0, strlen($host)) == $host)
echo "1\n";
else
echo "0\n";
mysqli_close($link);
echo "Done\n";
?>
--EXPECTF--
%s.%s
Location: mysql://%s.%s:%d/user=%s@%s
0
Done

Просмотреть файл

@ -0,0 +1,72 @@
--TEST--
Azure redirection test for servers when mysqlnd_azure.enableRedirect="off"
--INI--
mysqlnd_azure.enableRedirect="off"
--SKIPIF--
<?php
require_once('skipif.inc');
?>
--FILE--
<?php
require_once("connect.inc");
//Step 1: check option setting
$tmp = ini_get("mysqlnd_azure.enableRedirect");
echo $tmp."\n";
if (strcmp($tmp, "off")!=0)
{
printf("[001] mysqlnd_azure.enableRedirect not set to off, got '%s'\n", $tmp);
die();
}
//Step 2: check connection result when use SSL
$link = mysqli_init();
$ret = @mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL);
if (!$ret || !is_object($link))
{
printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n - [%d] %s with ssl\n",
$host, $user, $db, $port, $socket, mysqli_connect_errno(), mysqli_connect_error());
die();
}
echo $link->host_info."\n";
$last_message = $link->info;
//Server supports redirection
if(strlen($last_message) > 27 && strcmp(substr($last_message, 0, strlen("Location:")), "Location:")==0) {
if(substr($link->host_info, 0, strlen($host)) == $host)
echo "[003] pass\n";
else
echo "[003] fail\n";
}
else { //Server does not support redirection, use the proxy connection
if(substr($link->host_info, 0, strlen($host)) == $host)
echo "[003] pass\n";
else
echo "[003] fail\n";
}
mysqli_close($link);
//Step 3: check connection result when not use SSL
$link = mysqli_init();
$ret = @mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, NULL);
if (!$ret || !is_object($link))
{
printf("[004] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n - [%d] %s without ssl\n",
$host, $user, $db, $port, $socket, mysqli_connect_errno(), mysqli_connect_error());
die();
}
if(substr($link->host_info, 0, strlen($host)) == $host)
echo "[004] pass\n";
else
echo "[004] fail\n";
echo "Done\n";
?>
--EXPECTF--
off
%s
[003] pass
[004] pass
Done

Просмотреть файл

@ -0,0 +1,68 @@
--TEST--
Azure redirection test for servers when mysqlnd_azure.enableRedirect="on"
--INI--
mysqlnd_azure.enableRedirect="on"
--SKIPIF--
<?php
require_once('skipif.inc');
?>
--FILE--
<?php
require_once("connect.inc");
//Step 1: check option setting
$tmp = ini_get("mysqlnd_azure.enableRedirect");
echo $tmp."\n";
if (strcmp($tmp, "on")!=0)
{
printf("[001] mysqlnd_azure.enableRedirect not set to on, got '%s'\n", $tmp);
die();
}
//Step 2: check connection result when use SSL
$link = mysqli_init();
$ret = @mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL);
$last_message = "";
if($ret)
$last_message = $link->info;
//Server supports redirection
if(strlen($last_message) > 27 && strcmp(substr($last_message, 0, strlen("Location:")), "Location:")==0) {
if(substr($link->host_info, 0, strlen($host)) == $host)
echo "[003] fail\n";
else
echo "[003] pass\n";
}
else { //Server does not support redirection
$lastError = error_get_last()["message"];
if (strpos($lastError, "Connection aborted because redirection is not enabled on the MySQL server or the network package doesn't meet meet redirection protocol.") !== false)
echo "[003] pass\n";
else
echo "[003] fail\n";
}
mysqli_close($link);
//Step 3: check connection result when not use SSL
$link = mysqli_init();
$ret = @mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, NULL);
if ($ret)
{
printf("[004] When enableRedirect=on, connect without SSL expects failure, got pass\n");
die();
}
$lastError = error_get_last()["message"];
if (strpos($lastError, "mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL.") !== false)
echo "[004] pass\n";
else
echo "[004] fail\n";
echo "Done\n";
?>
--EXPECTF--
on
[003] pass
[004] pass
Done

Просмотреть файл

@ -0,0 +1,72 @@
--TEST--
Azure redirection test for servers when mysqlnd_azure.enableRedirect="preferred"
--INI--
mysqlnd_azure.enableRedirect="preferred"
--SKIPIF--
<?php
require_once('skipif.inc');
?>
--FILE--
<?php
require_once("connect.inc");
//Step 1: check option setting
$tmp = ini_get("mysqlnd_azure.enableRedirect");
echo $tmp."\n";
if (strcmp($tmp, "preferred")!=0)
{
printf("[001] mysqlnd_azure.enableRedirect not set to preferred, got '%s'\n", $tmp);
die();
}
//Step 2: check connection result when use SSL
$link = mysqli_init();
$ret = @mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL);
if (!$ret || !is_object($link))
{
printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n - [%d] %s with ssl\n",
$host, $user, $db, $port, $socket, mysqli_connect_errno(), mysqli_connect_error());
die();
}
echo $link->host_info."\n";
$last_message = $link->info;
//Server supports redirection
if(strlen($last_message) > 27 && strcmp(substr($last_message, 0, strlen("Location:")), "Location:")==0) {
if(substr($link->host_info, 0, strlen($host)) == $host)
echo "[003] fail\n";
else
echo "[003] pass\n";
}
else { //Server does not support redirection, use the proxy connection
if(substr($link->host_info, 0, strlen($host)) == $host)
echo "[003] pass\n";
else
echo "[003] fail\n";
}
mysqli_close($link);
//Step 3: check connection result when not use SSL
$link = mysqli_init();
$ret = @mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, NULL);
if (!$ret || !is_object($link))
{
printf("[004] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n - [%d] %s without ssl\n",
$host, $user, $db, $port, $socket, mysqli_connect_errno(), mysqli_connect_error());
die();
}
if(substr($link->host_info, 0, strlen($host)) == $host)
echo "[004] pass\n";
else
echo "[004] fail\n";
echo "Done\n";
?>
--EXPECTF--
preferred
%s
[003] pass
[004] pass
Done

Просмотреть файл

@ -33,22 +33,22 @@ fclose($fp);
--EXPECTF-- --EXPECTF--
*** Testing mysqli in web server: basic functionality *** *** Testing mysqli in web server: basic functionality ***
step1: redirect enabled, non-persistent connection step1: redirect enabled, non-persistent connection
mysqlnd_azure.enabled: On mysqlnd_azure.enableRedirect: preferred
%s %s
Location: mysql://%s:%d/user=%s Location: mysql://%s:%d/user=%s
0 0
step2: redirect enabled, persistent connection step2: redirect enabled, persistent connection
mysqlnd_azure.enabled: On mysqlnd_azure.enableRedirect: preferred
%s %s
Location: mysql://%s:%d/user=%s Location: mysql://%s:%d/user=%s
0 0
step3: redirect disabled, non-persistent connection step3: redirect disabled, non-persistent connection
mysqlnd_azure.enabled: Off mysqlnd_azure.enableRedirect: off
%s %s
Location: mysql://%s:%d/user=%s Location: mysql://%s:%d/user=%s
1 1
step4: redirect disabled, persistent connection step4: redirect disabled, persistent connection
mysqlnd_azure.enabled: Off mysqlnd_azure.enableRedirect: off
%s %s
0 0

Просмотреть файл

@ -1,11 +1,11 @@
<?php <?php
require_once("connect.inc"); require_once("connect.inc");
ini_set("mysqlnd_azure.enabled", "on"); ini_set("mysqlnd_azure.enableRedirect", "preferred");
echo "step1: redirect enabled, non-persistent connection \n"; echo "step1: redirect enabled, non-persistent connection \n";
{ {
echo "mysqlnd_azure.enabled: ", ini_get("mysqlnd_azure.enabled") == true?"On":"Off", "\n"; echo "mysqlnd_azure.enableRedirect: ", ini_get("mysqlnd_azure.enableRedirect"), "\n";
$link = mysqli_init(); $link = mysqli_init();
$ret = mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL); $ret = mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL);
if (!$ret || !is_object($link)) if (!$ret || !is_object($link))
@ -25,7 +25,7 @@ echo "step1: redirect enabled, non-persistent connection \n";
echo "step2: redirect enabled, persistent connection \n"; echo "step2: redirect enabled, persistent connection \n";
{ {
echo "mysqlnd_azure.enabled: ", ini_get("mysqlnd_azure.enabled") == true?"On":"Off", "\n"; echo "mysqlnd_azure.enableRedirect: ", ini_get("mysqlnd_azure.enableRedirect"), "\n";
$link = mysqli_init(); $link = mysqli_init();
$ret = mysqli_real_connect($link, "p:".$host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL); $ret = mysqli_real_connect($link, "p:".$host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL);
if (!$ret || !is_object($link)) if (!$ret || !is_object($link))
@ -43,11 +43,11 @@ echo "step2: redirect enabled, persistent connection \n";
mysqli_close($link); mysqli_close($link);
} }
ini_set("mysqlnd_azure.enabled", 0); ini_set("mysqlnd_azure.enableRedirect", "off");
echo "step3: redirect disabled, non-persistent connection \n"; echo "step3: redirect disabled, non-persistent connection \n";
{ {
echo "mysqlnd_azure.enabled: ", ini_get("mysqlnd_azure.enabled") == true?"On":"Off", "\n"; echo "mysqlnd_azure.enableRedirect: ", ini_get("mysqlnd_azure.enableRedirect"), "\n";
$link = mysqli_init(); $link = mysqli_init();
$ret = mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL); $ret = mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL);
if (!$ret || !is_object($link)) if (!$ret || !is_object($link))
@ -67,7 +67,7 @@ echo "step3: redirect disabled, non-persistent connection \n";
echo "step4: redirect disabled, persistent connection \n"; echo "step4: redirect disabled, persistent connection \n";
{ {
echo "mysqlnd_azure.enabled: ", ini_get("mysqlnd_azure.enabled") == true?"On":"Off", "\n"; echo "mysqlnd_azure.enableRedirect: ", ini_get("mysqlnd_azure.enableRedirect"), "\n";
$link = mysqli_init(); $link = mysqli_init();
$ret = mysqli_real_connect($link, "p:".$host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL); $ret = mysqli_real_connect($link, "p:".$host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL);
if (!$ret || !is_object($link)) if (!$ret || !is_object($link))

Просмотреть файл

@ -32,19 +32,19 @@ fclose($fp);
--EXPECTF-- --EXPECTF--
*** Testing pdo_mysql in web server: basic functionality *** *** Testing pdo_mysql in web server: basic functionality ***
step1: redirect enabled, non-persistent connection step1: redirect enabled, non-persistent connection
mysqlnd_azure.enabled: On mysqlnd_azure.enableRedirect: preferred
%s %s
0 0
step2: redirect enabled, persistent connection step2: redirect enabled, persistent connection
mysqlnd_azure.enabled: On mysqlnd_azure.enableRedirect: preferred
%s %s
0 0
step3: redirect disabled, non-persistent connection step3: redirect disabled, non-persistent connection
mysqlnd_azure.enabled: Off mysqlnd_azure.enableRedirect: off
%s %s
1 1
step4: redirect disabled, persistent connection step4: redirect disabled, persistent connection
mysqlnd_azure.enabled: Off mysqlnd_azure.enableRedirect: off
%s %s
0 0
===DONE=== ===DONE===

Просмотреть файл

@ -1,11 +1,11 @@
<?php <?php
require_once("connect.inc"); require_once("connect.inc");
ini_set("mysqlnd_azure.enabled", "on"); ini_set("mysqlnd_azure.enableRedirect ", "preferred");
echo "step1: redirect enabled, non-persistent connection \n"; echo "step1: redirect enabled, non-persistent connection \n";
{ {
echo "mysqlnd_azure.enabled: ", ini_get("mysqlnd_azure.enabled") == true?"On":"Off", "\n"; echo "mysqlnd_azure.enableRedirect: ", ini_get("mysqlnd_azure.enableRedirect"), "\n";
$conn = NULL; $conn = NULL;
try { try {
$conn = new PDO($pdo_dsn, $user, $passwd, $conn = new PDO($pdo_dsn, $user, $passwd,
@ -27,7 +27,7 @@ echo "step1: redirect enabled, non-persistent connection \n";
echo "step2: redirect enabled, persistent connection \n"; echo "step2: redirect enabled, persistent connection \n";
{ {
echo "mysqlnd_azure.enabled: ", ini_get("mysqlnd_azure.enabled") == true?"On":"Off", "\n"; echo "mysqlnd_azure.enableRedirect: ", ini_get("mysqlnd_azure.enableRedirect"), "\n";
$conn = NULL; $conn = NULL;
try { try {
$conn = new PDO($pdo_dsn, $user, $passwd, $conn = new PDO($pdo_dsn, $user, $passwd,
@ -47,11 +47,11 @@ echo "step2: redirect enabled, persistent connection \n";
$conn = NULL; $conn = NULL;
} }
ini_set("mysqlnd_azure.enabled", 0); ini_set("mysqlnd_azure.enableRedirect", "off");
echo "step3: redirect disabled, non-persistent connection \n"; echo "step3: redirect disabled, non-persistent connection \n";
{ {
echo "mysqlnd_azure.enabled: ", ini_get("mysqlnd_azure.enabled") == true?"On":"Off", "\n"; echo "mysqlnd_azure.enableRedirect: ", ini_get("mysqlnd_azure.enableRedirect"), "\n";
$conn = NULL; $conn = NULL;
try { try {
$conn = new PDO($pdo_dsn, $user, $passwd, $conn = new PDO($pdo_dsn, $user, $passwd,
@ -73,7 +73,7 @@ echo "step3: redirect disabled, non-persistent connection \n";
echo "step4: redirect disabled, persistent connection \n"; echo "step4: redirect disabled, persistent connection \n";
{ {
echo "mysqlnd_azure.enabled: ", ini_get("mysqlnd_azure.enabled") == true?"On":"Off", "\n"; echo "mysqlnd_azure.enableRedirect: ", ini_get("mysqlnd_azure.enableRedirect"), "\n";
$conn = NULL; $conn = NULL;
try { try {
$conn = new PDO($pdo_dsn, $user, $passwd, $conn = new PDO($pdo_dsn, $user, $passwd,

Просмотреть файл

@ -20,7 +20,7 @@
} }
include_once('connect.inc'); include_once('connect.inc');
ini_set("mysqlnd_azure.enabled", "on"); ini_set("mysqlnd_azure.enableRedirect ", "preferred");
$conn = NULL; $conn = NULL;
try { try {
$conn = new PDO($pdo_dsn, $user, $passwd, $conn = new PDO($pdo_dsn, $user, $passwd,

Просмотреть файл

@ -4,6 +4,7 @@
if(!link) if(!link)
die("skip mysqli_init failed"); die("skip mysqli_init failed");
ini_set("mysqlnd_azure.enableRedirect", "preferred");
$ret = mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL); $ret = mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL);
if (!$ret) if (!$ret)
die(sprintf("skip Can't connect to MySQL Server with ssl - [%d] %s", mysqli_connect_errno(), mysqli_connect_error())); die(sprintf("skip Can't connect to MySQL Server with ssl - [%d] %s", mysqli_connect_errno(), mysqli_connect_error()));