Delays when reading HANGUPCAUSE

When trying to read HANGUPCAUSE variable using fastagi (phpagi + agispeedy) it happens very often that I have to wait for response tens of seconds while the connection itself has already ended. What can cause the problem?