php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78845 mysqli_connect() causes malfunctions of curl
Submitted: 2019-11-20 22:36 UTC Modified: 2019-12-04 09:24 UTC
Votes:15
Avg. Score:4.7 ± 0.6
Reproduced:15 of 15 (100.0%)
Same Version:11 (73.3%)
Same OS:6 (40.0%)
From: gilperon at gmail dot com Assigned:
Status: Open Package: *General Issues
PHP Version: 7.2.24 OS: Centos 7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: gilperon at gmail dot com
New email:
PHP Version: OS:

 

 [2019-11-20 22:36 UTC] gilperon at gmail dot com
Description:
------------
Hi,

I have found a very serious and easy to reproduce bug happening with CURL on latest PHP 7.2.X (which is 7.2.24).

Just run the code below on your server running PHP+APACHE+MARIADB:

<?php

$curl = curl_init();

$opts = array();

$opts[CURLOPT_URL] = "https://www.sitepor500.com.br";

curl_setopt_array($curl,$opts);

echo curl_exec($curl);

?>

It will work just fine, I mean, you will see the contents of the page on CURLOPT_URL. Now JUST ADD one single line of code to it and the bug will happen:

<?php

$conn = mysqli_connect("localhost","root","your_password");

$curl = curl_init();

$opts = array();

$opts[CURLOPT_URL] = "https://www.sitepor500.com.br";

curl_setopt_array($curl,$opts);

echo curl_exec($curl);

?>

Incredibly, just adding a connection to a local database will make CURL fetch the content of the URL specified at CURLOPT_URL as "" (empty string). This happens with any URL.

Test script:
---------------
<?php

$conn = mysqli_connect("localhost","root","your_password");

$curl = curl_init();

$opts = array();

$opts[CURLOPT_URL] = "https://www.sitepor500.com.br";

curl_setopt_array($curl,$opts);

echo curl_exec($curl);

?>

Expected result:
----------------
You should see the URL content

Actual result:
--------------
Nothing is shown

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-11-20 22:41 UTC] stas@php.net
-Package: PHP Language Specification +Package: *General Issues
 [2019-11-20 22:45 UTC] cmb@php.net
This might be related to bug #78824.
 [2019-11-21 09:08 UTC] cmb@php.net
-Summary: Serious bug with latest PHP 7.2.24 bug +Summary: mysqli_connect() causes malfunctions of curl
 [2019-11-21 12:23 UTC] gilperon at gmail dot com
Guys I think it has something related to SSL!

On the test code I provided you if you change https://www.sitepor500.com.br to any domain that DOES NOT have SSL it will work. Try changing https://www.sitepor500.com.br to any domain that does not force https redirection and the bug goes away.

So it clearly only happen when the destination domain uses SSL.

note: this bug does not happen when using `file_get_contents`.
 [2019-11-25 16:02 UTC] lcobucci@php.net
This should be solved on 7.2.5 with Nikita's patch http://git.php.net/?p=php-src.git;a=commit;h=4f984a2fdb3815361f83013c23af0ff5d6d63d67 of bug #78775
 [2019-11-26 10:48 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2019-11-26 10:48 UTC] cmb@php.net
> This should be solved on 7.2.5 with Nikita's patch […]

Ah, good catch!  It's 7.2.25, though.

@gilperon, can you please try with a current Git snapshot?
 [2019-11-26 10:54 UTC] cmb@php.net
> […] can you please try with a current Git snapshot?

I mean with PHP 7.2.25 (which has already been released).
 [2019-11-26 19:18 UTC] gilperon at gmail dot com
Hey guys,

Yesterday it came back to work, RIGHT after I updated the PHP version to 7.2.25. However today, the bug came back to happening again! It's pretty strange, cause I didnt update anything today on my CENTOS server.

Really weird. I also clean installed Centos 7 on a new cloud, installed LAMP with PHP to 7.2.25 and the bug also happens on a clean install. It's pretty easy to check it, just run the code with MYSQLI and CURL using HTTPS and it happens.

HOWEVER if I remove HTTPS from the CURL it works just fine.
 [2019-11-26 21:00 UTC] cmb@php.net
-Status: Feedback +Status: Open -Assigned To: cmb +Assigned To:
 [2019-12-04 09:24 UTC] nikic@php.net
To clarify, running under strace should be as simple as "strace php script.php".
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sat Oct 31 08:01:23 2020 UTC