Skip to content

Add option to configure MARS on SqlServer Connections#20113

Merged
taylorotwell merged 1 commit into
laravel:5.4from
rodrigopedra:patch-1
Jul 18, 2017
Merged

Add option to configure MARS on SqlServer Connections#20113
taylorotwell merged 1 commit into
laravel:5.4from
rodrigopedra:patch-1

Conversation

@rodrigopedra

@rodrigopedra rodrigopedra commented Jul 17, 2017

Copy link
Copy Markdown
Contributor

As stated in this docs from Microsoft:

https://github.com/Microsoft/msphpsql/wiki/Recommendations-for-improving-the-performance-of-PDO_SQLSRV-and-SQLSRV#1-multiple-active-result-sets-mars

MARS is enabled by default in both SQLSRV and PDO_SQLSRV drivers. There can be some performance drop when MARS is enabled. Existing code optimized to run in the non-MARS world may show a performance dip when run un-modified with MARS.

This PR adds the ability to disable MARS on a SqlServer connection

As stated in this docs from Microsoft:

https://github.com/Microsoft/msphpsql/wiki/Recommendations-for-improving-the-performance-of-PDO_SQLSRV-and-SQLSRV#1-multiple-active-result-sets-mars

> MARS is enabled by default in both SQLSRV and PDO_SQLSRV drivers. There can be some performance drop when MARS is enabled. Existing code optimized to run in the non-MARS world may show a performance dip when run un-modified with MARS.

This PR adds the ability to configure MARS on a SqlServer connection
$arguments['TrustServerCertificate'] = $config['trust_server_certificate'];
}

if (isset($config['multiple_active_resultsets']) && $config['multiple_active_resultsets'] === false) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$arguments['MultipleActiveResultSets'] = $config['multiple_active_resultsets'] ?? true;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for your observation, Laravel 5.4 still supports PHP 5.6 which does not have the null coalesce operator, so, unfortunately that cannot be used. I hope it gets merged on Laravel 5.4 because that is what I use in production.

Also the argument should only be set to the string value 'false' (not the false boolean value) only when explicitly disabled, because:

  1. MARS is enabled by default (see the Microsoft docs linked above)
  2. The buildConnectString(...) method uses sprintf so a false boolean value would be outputted as the string '0', and if you look in Microsoft documentation linked above the added option to the connectiion string should be MultipleActiveResultSets=false
  3. I used the $config['pooling'] (a few lines above) as an example on how to do it.

@taylorotwell taylorotwell merged commit c27a982 into laravel:5.4 Jul 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants