Question: I have a PHP page where the header and footer are PHP includes.

I want to know if there is any possibility of the includes loading asynchronously - or does PHP gather all the files required, compile them and send them as one file?

The reason I ask is that I've seen an interesting PHP app that seemed to keep the connection open and do things in sequence before closing the connection - I wondered if that's what happens with includes.

PHP version is 5.3.6

EDIT:
What I actually want is for the page to load all at once, to prevent my layout mashing as each bit loads. Sorry to any who misunderstood this

Answer: 
Generally any output will be output as it is generated.

```
echo 'A';
sleep(1000);
echo 'B';
sleep(1000);
echo 'C';

```

This slowly outputs "ABC". Includes are included when they are encountered, the same way `echo` outputs anything at that specific point. It's all in order, never asynchronously.

A web server *may* buffer all output before sending any of it to the client. In the above example, you'd receive "ABC" all together after 2 seconds of nothing.
I use the following architecture when loading a page on my application:

index.php

```
<script src="path/to/js/lib/jslib.js" type="text/javascript"></script>

window.addEvent('load', function()
{
    BuildPg(PgStatus); //PgStatus is a variable I use in a state machine to build different pages
});

<form>
<div id="DivPgTop"></div>
<div id="DivPgMiddle"></div>
<div id="DivPgBottom"></div>
</form>

```

This is the entire index.php

In my jslib.js I have functions like:

```
function BuildPg(Pg) {
    BuildPgTop(Pg);
    BuildPgMiddle(Pg);
    BuildPgBottom(Pg);
}

function BuildPgTop(Pg) {
    var Content="";
    if (Pg == 1) {
        Content = function_a(); // function_a builds the top of the page
    else if (Pg == 2) {
        Content = function_b();
    etc...
    }

    document.getElementById("DivPgTop").innerHTML = Content; //here is where I load the top of the page
}

```

And I do the same for the other parts of the page Middle and Bottom.

Using this framework, if you changed my BuildPg() function to something like:

```
function BuildPg(Pg) {
    BuildPgTop(Pg);
    sleep(foo);
    BuildPgMiddle(Pg);
    sleep(bar);
    BuildPgBottom(Pg);
}

```

Your user would experience the top of the page loading first, a delay, the middle of the page, another delay, and the bottom.

And if you change the order of the function calls you could even have the bottom of the page load first, then the middle and the top.

I hope this makes sense. Good luck!