PHP: How to Flush the Buffer (HTML) Before Processing

Scenario:
You want to display a message “Please wait, we are processing your request”.

PHP Code:



Please wait, we are processing your request

Problem:
You need to wait for the process_request() finished before the message shows up.

Solution:

Well, if you’ve been coding with PHP for a while, you will know the ob_xxx functions which are designed to manipulate the output buffer.

Most of solutions from Google I’ve found out are




Please wait, we are processing your request

This will work out in this simple example. But, in reality, you may need to include some PHP files. In my case, I need to include(‘wp-config.php’) and this solution somehow doesn’t work for me.

I tried to search the WordPress source code to see how it uses ob_xxx functions.

And, here is what I get




Please wait, we are processing your request

And it works!

Share and Enjoy

    FacebookTwitterGoogle PlusLinkedInStumbleUponPinterestRedditTumblrDiggEmailPrint

Related Posts