On flush in the php implementation of the TBufferedTransport it doesn't clear the internal buffer before calling the underlying write function. However the write function in TBufferedTransport does.
If a write on the underlying transport fails when we call flush, the internal buffer won't be cleared.
This causes some interesting issues when this happens. If you happen to call the same function twice (first call fails to write, but the second one succeeds), it will call the function on the server with the data provided in the first call, rather than your current call.