Skip to content
Advertisement

PHP AJAX echo json data before then sleep

I have tried out couple answers here but none worked.

I have this basic honeypot script:

JavaScript

I am trying to echo the json message and then sleep. But now it is first do sleep then echo the message. Any idea how to do it the good way?

Advertisement

Answer

Most likely the echo’d data is just being buffered rather than sent until sleep finishes and the request completes. Try using flush() to force pushing the output to the client:

JavaScript

If this fails, you may find padding the output will help meet the server/browser’s minimum length requirement to flush/display the data:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement