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?
Welcome to SitePoint.
You can browse the source code for PHP here, that should give you some insight into its internal workings.