|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 06 16:00:01 2025 UTC |
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.1no 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...)