Question

I am not sure what to really name this question, and I am sure it might not be really clear. But here it is:

What are the right procedural steps that PHP goes through when loading a single webpage? Are there call events or "something" that I can use to see the process? Maybe something along the lines, (1) server request initiated, (2) start processing PHP code, (3) finish processing PHP code, (4) start loading HTML, (5) start loading JS, (6) done loading the php?

Was it helpful?

Solution

Here's how it works:

  • PHP runs
  • PHP outputs stuff
  • Stuff gets sent to browser.

It doesn't matter what the "stuff" is. Typically it will be HTML, but it could be an image (using imagecreate and related functions), it could be JavaScript (not sure why you'd want to do this), or even CSS (even less likely). PHP can output JSON. Heck, I seem to recall reading about PHP functions that would let you generate SWF files!

Once PHP is done running, the browser then receives what it sends and deals with it. The browser doesn't know that PHP had anything to do with it. As far as it's concerned, it is whatever the Content-Type header says it is.

This is why PHP can generate JavaScript inline (<script>alert(<?php echo 123; ?>);</script>) but not the other way around. The browser doesn't care, it just sees the result.

OTHER TIPS

Php is a module in the webserver. You need the correct mime type .php, php5 etc. registered. Then the php script behave like a normal php installation when you run the script in the console. Hence there isn't such thing like main entry, end entry etc. Script starts from the first line.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top