php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71613 nonblocking UDP stream_socket_recvfrom() memory leak
Submitted: 2016-02-16 21:45 UTC Modified: -
Votes:5
Avg. Score:4.4 ± 0.8
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:2 (50.0%)
From: jnelson at archive dot org Assigned:
Status: Open Package: Performance problem
PHP Version: 5.5.32 OS: Ubuntu
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jnelson at archive dot org
New email:
PHP Version: OS:

 

 [2016-02-16 21:45 UTC] jnelson at archive dot org
Description:
------------
While coding a UDP server with stream_socket_recvfrom(), I found a memory leak when (a) the stream is set to nonblocking mode, (b) the optional $address reference is passed, and (c) no data is ready.  If $address is not passed, there is no leak.

It appears the leak only occurs if there's some traffic on the socket, meaning that this won't happen simply listening on a quiet port.  I'm including two scripts, client.php and server.php, which must be run together for the server script to exhibit the leak.

Test script:
---------------
client.php: http://archive.org/~jnelson/client.php.txt
server.php: http://archive.org/~jnelson/server.php.txt

Expected result:
----------------
Expect memory usage to remain roughly the same for the duration of execution.

Actual result:
--------------
server.php's memory usage gradually increases over time, but only if $address is requested in the call to stream_socket_recvfrom().

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-22 15:42 UTC] paul dot smith at deepseaelectronics dot com
I'm having this same problem on PHP 7.4.16 and 8.0.3. Both are running as FPM on CentOS 7.

The issue seems to happen when stream_socket_recvfrom() is called multiple times between calls to stream_select().

A temporary workaround would be to only read a single packet after each select but this is inefficient as we have to go around the entire main loop again instead of looping until recvfrom returns false.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue May 17 18:05:45 2022 UTC