php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26475 Memory leaking with sockets
Submitted: 2003-11-30 15:56 UTC Modified: 2003-12-01 03:56 UTC
From: ipa at beta dot lt Assigned:
Status: Not a bug Package: Sockets related
PHP Version: 4.3.4 OS: Linux/FreeBSD
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: ipa at beta dot lt
New email:
PHP Version: OS:

 

 [2003-11-30 15:56 UTC] ipa at beta dot lt
Description:
------------
Sockets' socket_read() left 8 bytes in memory.

Example configure:
'./configure' '--enable-versioning' '--enable-memory-limit' '--with-layout=GNU' '--with-zlib-dir=/usr' '--disable-all' '--with-regex=php' '--disable-cli' '--enable-ctype' '--with-dom=/usr/local' '--with-gd' '--enable-gd-native-ttf' '--enable-gd-jis-conv' '--with-freetype-dir=/usr/local' '--with-jpeg-dir=/usr/local' '--with-png-dir=/usr/local' '--with-xpm-dir=/usr/local' '--with-mysql=/usr/local' '--enable-overload' '--with-pcre-regex=yes' '--enable-posix' '--enable-session' '--enable-sockets' '--enable-tokenizer' '--with-expat-dir=/usr/local' '--enable-xml' '--with-zlib=yes' '--with-apxs2=/usr/local/sbin/apxs' '--with-imap=/usr/local' '--with-imap-ssl=/usr/local' '--prefix=/usr/local' 'i386-portbld-freebsd4.8'

but reproducable on linux too.



Reproduce code:
---------------
function foo(){
	$socket = socket_create (AF_INET, SOCK_STREAM, 0); 
	$result = socket_connect ($socket, gethostbyname ('www.example.com'), 80); 
	$in = "HEAD / HTTP/1.0\r\n\r\n";
	
	socket_write ($socket, $in, strlen ($in)); 
	while ($out = socket_read ($socket, 2048)) { /* .. */ }
	
	socket_close ($socket);
}

foo();
echo memory_get_usage() . "<br>";
foo();
echo memory_get_usage() . "<br>";
foo();
echo memory_get_usage() . "<br>";


Expected result:
----------------
xxxxx bytes.
xxxxx bytes.
xxxxx bytes.

Actual result:
--------------
xxxxx bytes.
xxxxx + 8 bytes.
xxxxx + 16 bytes.
...
xxxxx + (n * 8) bytes.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-12-01 02:13 UTC] sniper@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is by design. Memory used by resources is freed in the request shutdown.

 [2003-12-01 03:26 UTC] ipa at beta dot lt
Hm. as i understand it's not possible to write long-running socket server ? because after ~1 mln recieved connections it'll rich all 8 MB memory limit??
 [2003-12-01 03:56 UTC] derick@php.net
Nope, it doesn't do that. Sniper was slightly wrong. If you do a socket_close it should clean up the resource, and it also does that. What you see here is most likely some of the performance tweaks in PHP. If you keep doing this in a loop you'll see that there is an upper limit on this.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Apr 08 06:01:25 2020 UTC