php在完成加载之前不会更新页面

I want to write a crawler script with php and it is necessery to show pages which is indexing online. however, php doesn't update page real time, sometimes it write a few echos together and wait until finishing loading, sometimes nothing seems in page until finishing loading.

Here is an example about what I'm talking:

<?php
echo '1<br>';
sleep(2);
echo '2<br>';
sleep(2);
echo '3<br>';
sleep(2);
echo '4<br>';
?>

I tried on wamp and lamp and results were same. is there any way to show echos real time?

note: I found an online crawler which has this feature.

Try using flush().

Another, more manual, way is to query the server multiple times via ajax or using something like Comet.

I suggest you use some JavaScript to self refresh the page and it can then be called after each routine to run the necessary php function.