Particle Publish not adding EndOfLine with each publish event?

So i have taken it up on myself to use the sparkcore library in PHP in my PHP API. However i am encountering a strange problem. I am noticing that only partial event data is received by the buffer and the data field gets pushed only when there is another event in the queue. So basically a single event is not pushed down by Particle.Publish immediately to the socket. Is that by design?

This is the block under where the sparkcore library is continuously listening on the socket. As per the definition of fgets in PHP, if the length parameter is not specified then it would read till a newline (which is included in the return value), or an EOF (whichever comes first). If no length is specified, it will keep reading from the stream until it reaches the end of the line.

if (($this->buff = trim(fgets($this->conn))) == '') {

From the looks of it, it looks like the it doesn’t publish the event data of the first event till second event is published. What is interesting though is that it is working fine if i use this url in the browser

What could be wrong?