Memory leak in fgets
<p>I have been playing with PHP sockets for some days when making a simple IRC bot for some other projects, the bot is up and running but i noticed that after a couple of hours it will have eaten up all memory available.</p>

<p>I have been doing some debugging with memory_get_usage() and after making sure that i null out all variables i use within my loops, the only thing that causes an increase in memory usage is "fgets()", and i cannot seem to figure out why it wont release its memory after using it.</p>

<p>Any ideas of what i have been doing wrong?</p>

<p>Psudo-code:</p>

<pre><code>$this-&gt;socket = stream_socket_client(server, port);
stream_set_blocking($this-&gt;socket, 0);
stream_set_timeout($this-&gt;socket, 600);

while(true) {
  usleep(500000);
  $data = fgets($this-&gt;socket, 8192);
  *work with data if strlen &gt; 0*
  $data = null;
}
</code></pre>

<p>Note that i have disabled blocking so that the bot can do some background tasks even when there are no activity on the channels it is watching.</p>

<p>Memory usage before and after calling fgets (the same result with stream_get_line):</p>

<pre><code>int(959504)
string(0) "" //Data returned from gets
int(967736)
</code></pre>

<p>Note that i am testing against an SSL-server, could this be some kind of SSL "overflow"?</p>

<p>Or if you want to look at the whole code for yourself: <a href="https://github.com/Ueland/VikingBot" rel="nofollow">https://github.com/Ueland/VikingBot</a></p>
