|  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: -
Avg. Score:4.5 ± 0.8
Reproduced:5 of 5 (100.0%)
Same Version:1 (20.0%)
Same OS:3 (60.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
Have you experienced this issue?
Rate the importance of this bug to you:

 [2016-02-16 21:45 UTC] jnelson at archive dot org
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:

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().


Add a Patch

Pull Requests

Add a Pull Request


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-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 21 09:01:29 2024 UTC