Bug #79051 [Opn->Fbk]: putenv variables not accessible to dependent functions in Windows CLI

From: Date: Wed, 01 Jan 2020 12:39:00 +0000
Subject: Bug #79051 [Opn->Fbk]: putenv variables not accessible to dependent functions in Windows CLI
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224642@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79051&edit=1 ID: 79051 Updated by: cmb@php.net Reported by: danielklein at airpost dot net Summary: putenv variables not accessible to dependent functions in Windows CLI -Status: Open +Status: Feedback Type: Bug -Package: Unknown/Other Function +Package: PHP options/info functions Operating System: Windows 10 PHP Version: 7.3.13 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: 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? Previous Comments: ------------------------------------------------------------------------ [2020-01-01 02:28:36] 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 02:24:52] 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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79051&edit=1

« previous php.bugs (#224642) next »