|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81029 SOAP HTTP socket not closing on object destruction
Submitted: 2021-05-11 10:32 UTC Modified: 2021-05-17 14:43 UTC
From: kdonaldson at staff dot nexigen dot digital Assigned:
Status: Open Package: SOAP related
PHP Version: 7.4.19 OS: macOS and Cent OS 7
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2021-05-11 10:32 UTC] kdonaldson at staff dot nexigen dot digital
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-> (ESTABLISHED)
php     4396 vagrant    4u  IPv4  53447      0t0     TCP homestead:57816-> (ESTABLISHED)
php     4396 vagrant    5u  IPv4  54451      0t0     TCP homestead:57818-> (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.

Test script:

function call(int $number) {
    $client = new SoapClient('');
    $response = $client->NumberToWords(['ubiNum' => $number]);
    return $response->NumberToWordsResult;

$numbers = array_fill(0, 10000, 1);

foreach ($numbers as $number) {

Expected result:
The socket to be closed when the SoapClient object falls out of scope or destructs

Actual result:
The socket stays open and contributes to the open file limit / file descriptor limit


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-05-11 11:27 UTC]
It seems to me we're missing to undo the refcount increment[1]
when the object is destroyed.

[1] <>
 [2021-05-17 14:43 UTC]
@cmb: As it's stored in a property, shouldn't that happen automatically when the object (and thus also its properties) are destroyed?
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Jun 18 02:01:23 2021 UTC