SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict jasongr's Avatar
    Join Date
    Jul 2004
    Location
    usa
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how the PHP engine interacts with the Web server

    Hello

    I have been wondering about some issue for some time now and I hope that someone will be able to clear it up for me.

    When a PHP page is sent to be parsed and then its results are sent via the Web server to the client is streaming taking place?
    Is the entire page first parsed generating a complete HTML page and only then is the page returned to the client?
    Or maybe the PHP engine sending pieces of the code as soon as they are ready to the Web server. Meaning that some output is being sent to the client while the rest of the page is still being processed.

    Here is a hypothetical example.
    Assume I wrap the entire page with:
    Code:
    ob_start();
    <html>
    ... content here
    </html>
    $content = ob_get_contents();
    ob_clean();
    print $content;
    Will that be a very inefficient in terms the time the client will have to wait for the reponse than simply writing:
    <html>
    ... content here
    </html>

    ?

    thanks in advance

  2. #2
    SitePoint Addict Quaint's Avatar
    Join Date
    May 2004
    Location
    Netherlands
    Posts
    219
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    when a document has an extension that your webserver recognises as a PHP file (usually .php, .phtml, etc) the ENTIRE document is send to the PHP engine to be parsed...

    Quaint Tech
    - Blog on web development and web technology.

  3. #3
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,576
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Alot of the mechanics of this really depend on if your script is running as a CGI executable or an in-process module of sort (EG ISAPI on IIS or as an Apache module).

    The way it generally works is that:

    1) Client requests script (we are going to call it index.php).
    2) Server recieves request, sees .php extension and sends it to the php interperter.
    3) If you are running in CGI mode, it fires up the php interperter. If in ISAPI it pipes it over to the appropriate module.
    4) PHP parses file, does what it is told.
    5) Non code parts, and nay echoed/printed content are fired off to the output butter.
    6) When full or flushed, the output buffer is sent to client.

    In real terms, unless you are running a very inefficent application, you are serving very large pages or your server is drastically underpowered/overloaded, you will notice little difference using both the above methods.

    Hope this helps.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •