On 14 Mar 2001 21:39:05 -0800, Lauri Vain <[EMAIL PROTECTED]> wrote:
>How does the behind the scenes work by PHP exactly go? Does the PHP thread
>remain active so long as the information is sent to the visitor? Or will PHP
>parse the code and send it to Apache which will send the data to the user
>itself?

1 Apache receives the request and determines that it's a PHP script.
2 PHP parses your code
3 PHP executes your code
4 PHP passes output back to Apache
5 Apache sends output to the browser (optionally through things like SSL)
6 Apache finishes request (e.g. logs it, closes a non-persistent connection)

The catch is that steps 4/5 may repeat - this depends on your output buffering
setup. PHP can wait and send everything when the script finishes, send output
in blocks or send every output from each echo/print immediately. (PHP can also
do things like compress that output on the fly, but that's a separate
conversation)

>The reason that I'm asking this is I'm writing a statistics add-on for one of
>my sites and was wondering whether the code below would give the time in
>which PHP parses the code or in which the data gets streamed to the user.

You'd get the time needed to read the file and either send it or add it to the
output buffer (depending on your output buffer config as mentioned above). By
the time your code is executed, PHP will have already parsed your script (with
the exception of things like conditional / variable include()s and require()s),
so you'd only get the time required to execute the code, not parse it.

If you want to get round-trip times including transmission to the user, you'd
need to have some way of getting the user's browser to record a second request,
which introduces a lot of potential variables. 

It might be interesting to see how something relying entirely on client-side
calculation like the code below would compare with other approaches (e.g.
Header("Location: measure.php?start=" . time()) where measure.php just does
$elapsed = time() - $start). It should remove almost all of the server-side
latency and, in theory, would give some reasonable indication of how long it
takes to transfer a file over the intermediate network connection, which would
give you a reasonable idea of available bandwidth.

(Disclaimer: completely untested code written just now which has never been
seen by anything other than vi. Caveat programmer.)

<html>
        <head>
                <script lang="javascript">
                        Start = new Date();

                        function record_elapsed() {
                                Now = new Date();
                                Elapsed = Now.getTime() - Start.getTime();
                                recordTimeImg = new Image();
                                recordTimeImg = "recorder.php?Elapsed=" + Elapsed;
                        }
                </script>
                <? flush(); /* send this as quickly as possible */ ?>
        </head>
        <body OnLoad="record_elapsed();">
                ...
                a fair amount of text / HTML
                ...
        </body>
</html>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to