[php-src] Issue #18990: SOAP HTTP socket not closing on object destruction
| From: | Sn0wCrack | Date: | Mon, 30 Jun 2025 23:38:23 +0000 |
| Subject: | [php-src] Issue #18990: SOAP HTTP socket not closing on object destruction | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-250352@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/18990
Author: Sn0wCrack
### Description
I originally reported this on the PHP bug tracker a few years ago: https://bugs.php.net/bug.php?id=81029
If a SoapClient object is constructed without specifying the 'keep_alive' option to false,
the socket never appears to be closed if it falls out of scope
The provided script should be able to reproduce this, you can check the open sockets by running the
script like: "php /path/to/script.php &" and using the resulting PID on
lsof -a
-p {pid}
You should slowly see a list of TCP connections slowly build up over time similar to this:
```
php 4396 vagrant 3u IPv4 53416 0t0 TCP
homestead:57814->ec2-52-7-155-169.compute-1.amazonaws.com:https (ESTABLISHED)
php 4396 vagrant 4u IPv4 53447 0t0 TCP
homestead:57816->ec2-52-7-155-169.compute-1.amazonaws.com:https (ESTABLISHED)
php 4396 vagrant 5u IPv4 54451 0t0 TCP
homestead:57818->ec2-52-7-155-169.compute-1.amazonaws.com:https (ESTABLISHED)
```
If instead you were to add ['keep_alive' => false] as the options parameter on the
SoapClient you'll see that the TCP connections don't appear to build up.
While I do understand the purpose of Keep Alive to keep a single connection open, I would assume
this is still a bug as the SoapClient has gone out of scope and new SoapClient objects don't
appear to reuse the existing connection and simply ignore it creating a new one.
File descriptors increase with each iteration of the loop:
```php
<?php
function call(int $number) {
$client = new SoapClient('https://www.dataaccess.com/webservicesserver/NumberConversion.wso?WSDL');
$response = $client->NumberToWords(['ubiNum' => $number]);
return $response->NumberToWordsResult;
}
$numbers = array_fill(0, 10000, 1);
foreach ($numbers as $number) {
call($number);
}
```
No increase in open file descriptors:
```php
<?php
function call(int $number) {
$client = new SoapClient('https://www.dataaccess.com/webservicesserver/NumberConversion.wso?WSDL',
['keep_alive' => false]);
$response = $client->NumberToWords(['ubiNum' => $number]);
return $response->NumberToWordsResult;
}
$numbers = array_fill(0, 10000, 1);
foreach ($numbers as $number) {
call($number);
}
```
### PHP Version
```plain
Originally replicated on PHP 7.4.19.
This has been anecdotally observed on PHP 8.0-8.3 as well.
```
### Operating System
macOS, Ubuntu 24.04 and RHEL7/8/9