php.net |  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
Votes:7
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 Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: bool at nexenservices dot com
New email:
PHP Version: OS:

 

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

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.

Patches

Pull Requests

History

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] mfischer@php.net
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) {
		    sleep(1);
			if (($buf = socket_read($socket, 1024)) !== FALSE ) {
				$buf = NULL;
				unset($buf);
			}
		}
--> 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] mfischer@php.net
Please test against http://snaps.php.net/php4-latest.tar.gz, 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, "www.php.net", "80");
	if ($moo)
	{
		socket_set_nonblock ($socket);
		while ($i<2000000) {
			$i++;
			if (($buf = socket_read($socket, 1024)) !== FALSE ) {
				$buf = NULL;
				unset($buf);
			}
		}
	}
?>

(add a sleep(1) into the while loop and it's fine...)
 [2002-06-07 16:47 UTC] sniper@php.net
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] mfischer@php.net
Please try the latest snapshot at http://snaps.php.net/win32/php4-win32-latest.zip 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] mfischer@php.net
As suggested, please try http://snaps.php.net/win32/php4-win32-latest.zip
 [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. 

Paul
 [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] phanto@php.net
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at http://snaps.php.net/. In case this was a documentation 
problem, the fix will show up soon at http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 07 21:01:27 2024 UTC