|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15485 memory ressource with socket_read()
Submitted: 2002-02-10 09:05 UTC Modified: 2002-06-15 12:05 UTC
Avg. Score:4.9 ± 0.3
Reproduced:5 of 5 (100.0%)
Same Version:4 (80.0%)
Same OS:5 (100.0%)
From: bool at nexenservices dot com Assigned:
Status: Closed Package: Sockets related
PHP Version: 4.x (latest of 07/06) OS: Windows 2000 Pro
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.
Block user comment
Status: Assign to:
Bug Type:
From: bool at nexenservices dot com
New email:
PHP Version: OS:


 [2002-02-10 09:05 UTC] bool at nexenservices dot com

I have a script (a bot, so it don't stop) wich connects to a server with socket_read(). It blocking mode it's work perfectly, but not in non-blocking mode : memory used by the function socket_read() seems to doesn't be released by PHP engine after the call. But when I had a sleep(1) just after the call, it's ok.

I tried with the Apache's Php module, and directly with the PHP executable. It's the same pb.

I know it's an experimental function, but I think it's can help for it's development.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-22 20:12 UTC] bool at nexenservices dot com
I checked this code under linux, all works fine, and the memory usage fastly stabilize. But under Win2k, with Php 4.2.0 it's always the same thing.
 [2002-05-04 19:06 UTC]
Please try current CVS HEAD and report back.
 [2002-06-05 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2002-06-07 13:47 UTC] grangeway2 at hotmail dot com
socket_set_nonblock ($socket);
		while (1) {
			if (($buf = socket_read($socket, 1024)) !== FALSE ) {
				$buf = NULL;
--> that code works fine.
As the original reporter says, if you remove sleep(1) it leaks memory. Approximately 1Mb of memory every few seoncds here.

This is against 4.2.1
 [2002-06-07 13:52 UTC]
Please test against, compile with --enable-debug and if the extension really leaks memory please paste the output after php ends (you will get a leak list [kind of] if there's really a leak).
 [2002-06-07 14:32 UTC] grangeway2 at hotmail dot com
no output after php terminates. the script is as follows:
error_reporting (E_NONE);
$socket = socket_create (AF_INET, SOCK_STREAM,  SOL_TCP);
$moo = socket_connect ($socket, "", "80");
	if ($moo)
		socket_set_nonblock ($socket);
		while ($i<2000000) {
			if (($buf = socket_read($socket, 1024)) !== FALSE ) {
				$buf = NULL;

(add a sleep(1) into the while loop and it's fine...)
 [2002-06-07 16:47 UTC]
reclassified where this belongs..

 [2002-06-08 05:14 UTC] bool at nexenservices dot com
It the same things. I try now whith PHP 4.2.1

(sorry, I can't compile with the last version)
 [2002-06-08 05:28 UTC]
Please try the latest snapshot at instead, this one contains the current development code.
 [2002-06-08 05:35 UTC] bool at boolsite dot net
I've just test with PHP 4.2.1 (always under Win2k Pro).

And there is always the same pb...
 [2002-06-08 05:42 UTC]
As suggested, please try
 [2002-06-08 06:26 UTC] grangeway2 at hotmail dot com
markus, the comment at 7june,2:32 pm was against the latest snapshot. 

PHP did not output anything when it terminated.
The code in that example was 'broken'. 
The fixed version of that code was to add a sleep(1).
Adding a usleep(100000)(i.e. 1sec), still exhibits the broken behaviour. 
Adding a sleep(1) command 'fixes' the memory issue. 

 [2002-06-08 06:35 UTC] bool at nexenservices dot com
Yes, sorry... I tried.

But it doesn't work... It's seem to be exactly like before...
 [2002-06-15 12:05 UTC]
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at In case this was a documentation 
problem, the fix will show up soon at
In case this was a website problem, the change will show
up on the site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Dec 06 14:01:27 2023 UTC