简体   繁体   中英

performance implications of php output buffering with Apache and MySQL

I am a bit confused about how php buffering works.

Let's say you have a php page foo.php and output_buffering = 4096 in php.ini , and Apache receives a get request for foo.php . foo.php starts executing, and as soon as 4096 bytes are ready, they are sent to Apache. Apache starts sending those 4096 bytes to the client.

Here's what I don't understand: what happens when there's a some nasty tracker callout, a javascript or an image that was sent to the browser. The browser gets hung up and is not talking back to Apache for a while, holding it up. Apache is not releasing MySQL thread, which is showing up as a "sleeper". Is this correct or am I completely off base here?

You're completely off base :)

what happens when there's a some nasty tracker callout, a javascript or an image that was sent to the browser

This isn't going to impact anything on the server side.

Each request that runs through PHP will

  1. Compile the needed PHP files to opt-code (unless caching is one)
  2. Execute the PHP opt-code
  3. Return the string results of the PHP opt-code to the browser

The buffering you're talking about occurs between steps 2 and 3. So, lets take your scenario.

  1. Request for a PHP URL is made
  2. The opt-code is compiled
  3. PHP Execution begins and starts to return html strings
  4. A string with a slow loading img tag is created
    • PHP continues to give output to apache
    • A separate http request is made for the image (or javascript code, or whatever, etc.)

It's the separate request that's impotent here. All PHP and Apache are doing is returning HTML to the browser. This HTML may produce an img or javasript tag that will call back to the same web-server, but those requests will be handled separately from the request that's producing the HTML for the existing page.

The browser doesn't get 'hung up' from downloading HTML data from the server. It continues to download the entire page, even if it is waiting on a JavaScript file to come down before it will actually show any of it.

Of course if the browser/server connection breaks for some reason you can get Apache hanging around waiting for ACKs until the connection times out, but this is not the usual case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM