socket_recv and memory leak
Posted: Mon Oct 26, 2009 12:47 pm
Hello community!
I have a little problem and hope somebody here may help.
Currently I have a small cli-deamon, that connects himself via sockets to a system and asks for statistics. After the data has been received i close that socket, transform the data and write them into a database.
Then I do the same with the next system.... and so on.
I've monitored the process with "memory_get_usage" and it looks like "socket_recv" has a memory leak (at least like i have implemented it).
After each look the used memory gets bigger. If I dont read any data, I dont have that problem.
This is my code (simplified):
Could anyone imagine, why this is happening?
Thanks for any help.
I'm running this script on RedHat Enterprise Linux 5.3 with PHP 5.1.6.
Update:
In PHP 5.2.9 the garbadge-collection works better. No memory leaks there.
If I change the usleep(100) into an sleep(1) I can observe, that the GC in 5.1.6 works, but mutch slower.
So there doesn't seem any answer to my problem beside upgrading. If anyone else has some other ideas, please feel wellcome to post them
I have a little problem and hope somebody here may help.
Currently I have a small cli-deamon, that connects himself via sockets to a system and asks for statistics. After the data has been received i close that socket, transform the data and write them into a database.
Then I do the same with the next system.... and so on.
I've monitored the process with "memory_get_usage" and it looks like "socket_recv" has a memory leak (at least like i have implemented it).
After each look the used memory gets bigger. If I dont read any data, I dont have that problem.
This is my code (simplified):
Code: Select all
while(true) {
usleep(100);
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$sock_data = @socket_connect($sock,$host, $port);
socket_write($sock, "some data please");
/* tryed it with socket_read. Same problem.
do {
$recv = '';
$recv = socket_read($sock, $buff, PHP_BINARY_READ);
if($recv != '') {
$readedContent .= $recv;
}
} while($recv != '');*/
while (($curRecived = @socket_recv($sock, $recv, 8192, MSG_WAITALL))) {
$readedContent .= $recv;
$recived += $curRecived;
}
socket_close($sock);
unset($sock);
//transorming [...]
//Cleanup
unset($readedContent);
unset($recv);
unset($recived);
unset($curRecived);
//choose next connection [...]
}
Thanks for any help.
I'm running this script on RedHat Enterprise Linux 5.3 with PHP 5.1.6.
Update:
In PHP 5.2.9 the garbadge-collection works better. No memory leaks there.
If I change the usleep(100) into an sleep(1) I can observe, that the GC in 5.1.6 works, but mutch slower.
So there doesn't seem any answer to my problem beside upgrading. If anyone else has some other ideas, please feel wellcome to post them