php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79051 putenv variables not accessible to dependent functions in Windows CLI
Submitted: 2020-01-01 02:24 UTC Modified: 2020-03-31 10:34 UTC
From: danielklein at airpost dot net Assigned: cmb (profile)
Status: Closed Package: PHP options/info functions
PHP Version: 7.3.13 OS: Windows 10
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: danielklein at airpost dot net
New email:
PHP Version: OS:

 

 [2020-01-01 02:24 UTC] danielklein at airpost dot net
Description:
------------
In Windows CLI, setting an environment with `putenv()`, such as "all_proxy" which is supposed to affect cURL, has no effect on later function calls.

The test script works as expected on Ubuntu CLI, but not Windows CLI.

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

function search() {
  $url = 'x3m.dev';

  $curl = curl_init();
  curl_setopt_array($curl, [
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => $url,
  ]);
  $data = curl_exec($curl);

  if (!$data) {
    throw new Exception('An error occurred while trying to process the request.');
  }
  return $data;
}

function do_curl_request() {
  echo getenv("all_proxy") . "\n\n";
  try {
    echo search();
  }
  catch (Exception $e) {
    echo $e->getMessage();
  }
  echo "\n\n";
}

echo "========== first run without proxy\n";
do_curl_request();

putenv("all_proxy=localhost:5678");
echo "========== second run with proxy override\n";
do_curl_request();


Expected result:
----------------
========== first run without proxy


<html>
<head></head>
<body>.</body>
</html>

========== second run with proxy override
localhost:5678

An error occurred while trying to process the request.



Actual result:
--------------
========== first run without proxy


<html>
<head></head>
<body>.</body>
</html>

========== second run with proxy override
localhost:5678

An error occurred while trying to process the request.



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-01-01 02:28 UTC] danielklein at airpost dot net
"Edit" won't let me edit the bug report.

Actual result:

========== first run without proxy


<html>
<head></head>
<body>.</body>
</html>

========== second run with proxy override
localhost:5678

<html>
<head></head>
<body>.</body>
</html>
 [2020-01-01 12:39 UTC] cmb@php.net
-Status: Open +Status: Feedback -Package: Unknown/Other Function +Package: PHP options/info functions -Assigned To: +Assigned To: cmb
 [2020-01-01 12:39 UTC] cmb@php.net
I cannot reproduce the reported behavior.  What do the putenv()
and getenv() calls return (use var_dump instead of echo or
ignoring the return value)?  Also, are you using NTS or ZTS
builds?
 [2020-01-02 10:32 UTC] danielklein at airpost dot net
-Status: Feedback +Status: Assigned
 [2020-01-02 10:32 UTC] danielklein at airpost dot net
The first var_dump(getenv('all_proxy')); returns bool(false).
var_dump(putenv('all_proxy=localhost:5678')); returns bool(true).
The second var_dump(getenv('all_proxy')); returns string(14) "localhost:5678".

It's the thread safe build:

PHP 7.3.9 (cli) (built: Aug 28 2019 09:28:48) ( ZTS MSVC15 (Visual C++ 2017) x64 )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.9, Copyright (c) 1998-2018 Zend Technologies
    with Xdebug v2.7.2, Copyright (c) 2002-2019, by Derick Rethans

Just to confirm, you did run this on Windows? The bug is not present on Ubuntu, and I assume other Linux varieties.
 [2020-01-02 10:51 UTC] cmb@php.net
-Status: Assigned +Status: Feedback
 [2020-01-02 10:51 UTC] cmb@php.net
Yes, I tested on Windows (PHP 7.3.13 x64 NTS and ZTS).

Obviously, in your case putenv() signals success, and getenv()
returns what it is supposed to.

Could you please try with PHP 7.3.13 and Xdebug disabled?

Thanks.
 [2020-01-02 12:08 UTC] danielklein at airpost dot net
-Status: Feedback +Status: Assigned
 [2020-01-02 12:08 UTC] danielklein at airpost dot net
I've tried with 7.3.9-7.3.13, & 7.4.0-7.4.1 (fresh downloads and installations of PHP >= 7.3.12).
7.3.13 & 7.4.1 both with Xdebug disabled still have the same behaviour as I reported before.
 [2020-01-02 12:10 UTC] danielklein at airpost dot net
This is what I've downloaded and installed today (in different directories):
- php-7.3.12-Win32-VC15-x64.zip
- php-7.3.13-Win32-VC15-x64.zip
- php-7.4.0-Win32-vc15-x64.zip
- php-7.4.1-Win32-vc15-x64.zip
 [2020-01-02 15:04 UTC] cmb@php.net
-Status: Assigned +Status: Verified
 [2020-01-02 15:04 UTC] cmb@php.net
Thanks for the further information!  I just tried with a ZTS
build, and now I could reproduce.  Apparently, I didn't test
a ZTS build before, even though I thought I did.  Sorry.

Anyhow, the problem is actually the missing part of bug #66265 for
ZTS, which has never been addressed (the other ticket had been
closed inadvertently).

TL;DR: libcurl() currently calls getenv() to retrieve the
environment variable, but in ZTS builds it is only set with
SetEnvironmentVariable(), so is not available to libcurl.

I'm afraid, though, that we can't do anything here without
coordination with libraries using getenv() to retrieve environment
variables.  I just wrote to the curl library mailing list[1];
let's see how that goes.

[1] <https://curl.haxx.se/mail/lib-2020-01/0006.html>
 [2020-02-13 09:25 UTC] cmb@php.net
-Status: Verified +Status: Analyzed
 [2020-02-13 09:25 UTC] cmb@php.net
Update: a patch which fixes this issue regarding libcurl has just
been landed[1].  It will take some time until this fix gets
releases and we can update to the new libcurl version.

[1] <https://github.com/curl/curl/commit/9dc350b60c1345aea548847de414c55468a4d123>
 [2020-03-31 10:34 UTC] cmb@php.net
-Status: Analyzed +Status: Closed
 [2020-03-31 10:34 UTC] cmb@php.net
libcurl 7.69.1 has been released which fixes this issue, and will
be used for the PHP 7.3.17 and 7.4.5 Windows builds, so I'm
closing this ticket.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Nov 25 00:01:23 2020 UTC