Skip to content

Commit b59bbbf

Browse files
committed
Merge branch 'fix/php_uname'
2 parents 6b45b96 + 697f8e8 commit b59bbbf

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/Elasticsearch/Connections/Connection.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ class Connection implements ConnectionInterface
112112

113113
private $lastRequest = array();
114114

115+
/**
116+
* @var string
117+
*/
118+
private $OSVersion = null;
119+
115120
public function __construct(
116121
callable $handler,
117122
array $hostDetails,
@@ -149,8 +154,8 @@ public function __construct(
149154
$this->headers['User-Agent'] = [sprintf(
150155
"elasticsearch-php/%s (%s %s; PHP %s)",
151156
Client::VERSION,
152-
php_uname("s"),
153-
php_uname("r"),
157+
PHP_OS,
158+
$this->getOSVersion(),
154159
phpversion()
155160
)];
156161

@@ -547,6 +552,22 @@ protected function getCurlRetryException(array $request, array $response): Elast
547552
return $exception;
548553
}
549554

555+
/**
556+
* Get the OS version using php_uname if available
557+
* otherwise it returns an empty string
558+
*
559+
* @see https://github.com/elastic/elasticsearch-php/issues/922
560+
*/
561+
private function getOSVersion(): string
562+
{
563+
if ($this->OSVersion === null) {
564+
$this->OSVersion = strpos(strtolower(ini_get('disable_functions')), 'php_uname') !== false
565+
? ''
566+
: php_uname("r");
567+
}
568+
return $this->OSVersion;
569+
}
570+
550571
/**
551572
* Construct a string cURL command
552573
*/

0 commit comments

Comments
 (0)