What actually happens after php interpreter parses code?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
blacktie524
Forum Newbie
Posts: 1
Joined: Mon Mar 07, 2011 8:42 pm

What actually happens after php interpreter parses code?

Post by blacktie524 »

What actually happens in the background after php interpreter parses code that says, open a database connection, execute curl request, etc.? So when a php script is run and the php interpreter parses the script and finds code that says open a database connection and perform a query, how does this actually happen? What goes on in the background that actually fulfills this request and performs the communication with the database?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: What actually happens after php interpreter parses code?

Post by Weirdan »

After php script is read and tokenized it's compiled into intermediary representation called bytecode. Compiled bytecode is interpreted by Zend Engine. It may contain calls to any extension functions e.g. mysql_connect() - and whenever such call is met execution is transferred to the native code of the extension called. Usually (but not necessarily) extensions are just wrappers for some external library (like libmysql), and they pass the execution to the library code, which is responsible for whatever the library is doing, like establishing tcp connection to mysql server and talking to it following appropriate protocol.
Post Reply