I was poking around the PHP 5.3.1 source tree, and decided to take a look at main.c. I was curious what was happening behind the scenes whenever PHP runs.
I was under the impression that any C or C++ program starts execution in a function named main, but I don’t see a function with that name in main.c.
Where does PHP code actually start executing (a different for command-line vs. MOD_PHP vs. CGI?), and what am I missing w/r/t no main function in the main.c file that would let me answer this question myself the next time?
I don’t think I’ve ever seen any clear answer to that kind of question on the Internet, but you might be interested by some paragraphs of the book Extending and Embedding PHP, which is probably the reference book when it comes to writting PHP extensions, and the internals of the PHP engine.
An interesting couple of sentences, quoting chapter 1 “The PHP Life Cycle”, is :
And, just after :
You’ll probably be able to find some pages on Google books, if you want to try reading a bit more…