microsoft / msphpsql

Microsoft Drivers for PHP for SQL Server
MIT License
1.8k stars 374 forks source link

sql lost connection if curl get ssl error #1422

Closed Itatsi closed 1 year ago

Itatsi commented 1 year ago

Hi^^ I hope I am in the right place with this question. I'm on Ubuntu 22.04 with php 8.1 and msodbcsql18. My sql connection is "disconnected?" if i get curl to produce an error with ssl.

Testscript:

<?php
$serverName = "mssql";
$connectionInfo = array("Database" => "###", "UID" => "###", "PWD" => "###", "TrustServerCertificate" => true);
$conn = sqlsrv_connect($serverName, $connectionInfo);
if ($conn === false) {
    die(print_r(sqlsrv_errors(), true));
}
$sql = 'SELECT TOP 1 * FROM TableName';
$stmt = sqlsrv_query($conn, $sql);
if ($stmt === false) {
    die(print_r(sqlsrv_errors(), true));
}
$ch = curl_init();
curl_setopt_array($ch, array( CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => 1, CURLOPT_VERBOSE => true));

curl_setopt($ch, CURLOPT_URL, 'https://google.de:80');
$result = curl_exec($ch);

echo $result . PHP_EOL;
$stmt = sqlsrv_query($conn, $sql);
if ($stmt === false) {
    die(print_r(sqlsrv_errors(), true));
}

Output:

*   Trying 142.251.36.195:80...
* Connected to google.de (142.251.36.195) port 80 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
*  CAfile: /etc/ssl/certs/ca-certificates.crt
*  CApath: /etc/ssl/certs
* error:0A00010B:SSL routines::wrong version number
* Closing connection 0

Array
(
    [0] => Array
        (
            [0] => 08S01
            [SQLSTATE] => 08S01
            [1] => -1
            [code] => -1
            [2] => [Microsoft][ODBC Driver 18 for SQL Server]SSL Provider: [error:0A000197:SSL routines::shutdown while in init]
            [message] => [Microsoft][ODBC Driver 18 for SQL Server]SSL Provider: [error:0A000197:SSL routines::shutdown while in init]
        )

    [1] => Array
        (
            [0] => 08S01
            [SQLSTATE] => 08S01
            [1] => -1
            [code] => -1
            [2] => [Microsoft][ODBC Driver 18 for SQL Server]Communication link failure
            [message] => [Microsoft][ODBC Driver 18 for SQL Server]Communication link failure
        )

)

do any of you have an idea what this could be?

v-makouz commented 1 year ago

This looks like it may be a local configuration issue. Can you try a basic connection without PHP? (isql -v -k "")

Itatsi commented 1 year ago

the connection with php works perfectly. As you can see in the test script, the $stmt is executed successfully before curl. However, if curl returns an ssl error, the DB connection also terminates. I have only been able to reproduce this behaviour with ubntu 22.04.

v-makouz commented 1 year ago

So the issue isn't with PHP driver?

absci commented 1 year ago

Close due to inactivity.