|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 16:00:01 2025 UTC |
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.