0

I have two different servers and a script like this:

echo "<div style=\"some style\">whatever</div>"; 
for($i=0;$i<150000;$i++) 
{ ... }

Now, I realized that on my first server the PHP-script will directly show me the whatever and then start going through the for loop. The second server though doesn't show the div, it directly starts with the loop. But I need the script to show first the HTML code and then do the rest of the script.

Is there a possibility to change this?

Thank you!

2
  • 1
    Are you referring to how it's being rendered by the browser or how it's being actually outputted via the server? Commented Jan 30, 2011 at 22:20
  • How its been outputted by the server! I need to have a message "Please wait..." while the php scripts is doing things But the server will show this after the script is finished. Commented Jan 30, 2011 at 23:15

3 Answers 3

5

Check your php.ini for output buffering

Sign up to request clarification or add additional context in comments.

Comments

3

You should try flushing right after the echo before the for-loop.

2 Comments

My guess is the output_buffering config directives are different on each server. If so, this answer should solve it.
The problem is, I dont have access to the php.ini, but I tried to put php_value output_buffering "0" into the htaccess file. The result was, that the server didnt react at all anymore and showed the typical error message (500 Internal Server Error). I tried ob_flush(), flush(), ob_start(), ob_end_flush() in any possible combination. But nothing changes.
1

What happen swhen you got to the website: Browser to server, hey dude, can I have this file? Server handles the request, searches for the file Server notices, hey, got a PHP script, lets parse it. The script goes into an infinite loop.

The script needs to finish before it can send it back to the browser, thus your output will be empty.

2 Comments

Yes, you are right. So how could I achieve, that a user will have a message "Please wait..." while the php script is doing things?
@phpheini Well I don't know what you want to do exactly, but you could do that with javascript and AJAX, you load a normal page with the javascript which in turn loads this script, which can take days but that doesn't matter as you can show anything to the user on the other page.. euh if I am not being clear tell me xD -- jQuery is an awesome wrapper for loading pages dynamically with javascirpt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.