Skip to main content

"How the sausage is made' tour of apache/php/mysql interaction


I am having trouble understanding how apache/php/mysql stack works on a low level (including interaction with the browser). Is there a good description somewhere (a book, a website, etc) that will walk me through the whole path and explaining how starting with a browser reqesting a url, http requests is being sent, how apache talks to php, how php talks to mysql (persistant and non-persistant connections), etc, etc. I want to understand what waits for what in this chain, where timeouts are handled, how long sockets are opened and closed. A book, an article maybe? There is a lot of documentation on each individual component, but I can't find a "walkthrough".



The explanations I se so far are very high-level: look, here's a happy cow, it goes to Bovine University, look - it's all shrink wrapped on the supermarket shelf. What I need is the sausage farm/slaughterhouse/truck/factory tour, starting with cow insemenation :)



[update] To this day I have not found a better way to learn about these things other than reading the source.


Source: Tips4allCCNA FINAL EXAM

Comments

  1. PHP and MySQL by example has a pretty basic picture of the process, which I think you probably already understand.

    Getting more in-depth than that picture though is a pretty long discussion. Ironically, you can read the book I just linked for a pretty good description. If you have more specific questions, I recommend opening new questions for them. Enjoy!

    ReplyDelete
  2. I have found a site that has, at least in part, contents from the book Advanced PHP Programming by George Schlossnagle.

    The site is located at: http://php.find-info.ru/php/016/toc.html. Specifically, the section on The PHP Request Life Cycle contains a lot of the nitty-gritty details, including some source code and diagrams.

    DISCLAIMER: IANAL, but considering that the book is still listed on Amazon, its possible the content linked to above breaks all sorts of codes, rules and/or laws. Its not my intention to proliferate or condone illegal or pirated materials, so if that be the case, please remove said links.

    ReplyDelete
  3. As far as I understand it apache receives the request, and works out what to do with it based on your .htaccess or config options. It then passes this request to PHP for parsing, if needed. PHP does two scans of the code, the first is the pre-parse, this picks up obvious flaws and runs functions on the top level(ignoring any in if statements, loops, includes, evals or lamda based functions), before parsing the page for real. Anything done with echo, I do believe, is returned as the standard out stream, and is returned to apache. If apache times the page out it sends the kill signal to PHP, which closes objects, prints the error messages if needed, before exiting. Once the page exits apache tends to headers and returns the page.

    I would love to know more about this though, so if anyone can explain it better or has a correction/expansion on my answer, I'd love to hear it.

    ReplyDelete
  4. The most obvious answer, is get a good book about the LAMP stack.

    A quick response (ask for more if you feel you need it)
    Browser contacts web server though HTTP protocol
    Server generates (let's leave how for the moment) an html result and posts it back.
    Each browser understands only http protocol (for the sake of this analysis).

    Now items such as icons, images, javascript etc, are just read from the apache server and "copied" to the browser. Same in plain html files.
    The difference is in php files (I am oversimplifying here). These are passed to the php module and the response (of the module) will be sent back to the browser.

    The php module is what understands php.
    Are we together here? if yes then:
    Php script may (or may not) require data from an MySQL server, it has to connect get them or manipulate them etc.

    Summarizing: Each of these operation is being done individually in a different process level. That's what makes it "simple".
    Ask for more information if you want something more specific.

    ReplyDelete

Post a Comment

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex