• Save
How PHP Works ?
Upcoming SlideShare
Loading in...5
×
 

How PHP Works ?

on

  • 24,920 views

little bit introduction about php start up.

little bit introduction about php start up.

Statistics

Views

Total Views
24,920
Views on SlideShare
24,806
Embed Views
114

Actions

Likes
13
Downloads
0
Comments
4

9 Embeds 114

http://www.slideshare.net 65
http://ardlian.net 31
http://www.linkedin.com 6
http://web.archive.org 5
http://ravirajsblog.blogspot.com 3
http://socialsyllabus.com 1
http://blog.w3classroom.com 1
http://hudsonccc.blackboard.com 1
https://www.linkedin.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

How PHP Works ? How PHP Works ? Presentation Transcript

  • How PHP works ? Ravi Raj
  • About the presenter ??
    • Have 4+ years Experience in Web development
    • Have worked on few good products like peerpower.com , itimes.com
    • currently working in shiksha.com @ infoedge india pvt. Ltd.
    • Know more about me http://ravirajsblog.blogspot.com/
  • PHP LIFE CYCLE :) It's EASY ??
    • Parsing – Groups of tokens are collected into simple, meaningful expressions.
    • Compilation – Expressions are translated into instruction (opcodes)
    • Scanning – The human readable source code is turned into tokens.
    • Execution – Opcode stacks are processed (one opcode at a time) to perform the scripted tasks.
    View slide
  • SOME FACTS -1
    • We never start any PHP daemon or anything by ourself. When we start Apache, it starts the PHP interpreter along itself...
    View slide
  • SOME FACTS -2
    • PHP is linked to Apache (In general term SAPI i.e. a Server API) using mod_php5.so module...
  • SOME FACTS -3
    • PHP as a whole consists of 3 modules (Core PHP, Zend Engine and Extension Layer)
  • SOME FACTS -4
    • Core PHP is the module which handles the requests, file streams, error handling and other such operations
  • SOME FACTS -5
    • Zend Engine(ZE) is the one which converts human readable code into machine understandable tokens/op-codes. Then it executes this generate code into a Virtual Machine.
  • SOME FACTS -6
    • Extensions are a bunch of functions, classes, streams made available to the PHP scripts, which can be used to perform certain tasks. For example, as we need mysql extension to connect to MySQL database using PHP
  • SOME FACTS -7
    • While Zend Engine executes the generated code, the script might require access to a few extensions. Then ZE passes the control to the extension module/layer which transfer back the control to ZE after completion of tasks.
  • Its Easy to understand !!! Right ??
    • OH!!! NO !!! … It's a overview only … Take a one more closer look now …
  • Let's START AGAIN :) -1
    • As we start Apache, it starts PHP interpreter
    • PHP calls MINIT method of each extension, which is being enabled. View your php.ini file to see the modules which are being enabled by default
    • MINIT refers to Module Initialization. Each Module Initialization method initializes and define a set of functions, classes which will be used by future page requests
  • STEP -2
    • A typical MINIT method looks like:
    • PHP_MINIT_FUNCTION(extension_name) {
    • /* Initialize functions, classes etc */
    • }
  • STEP -2 more ...
    • When a page request is being made, SAPI layer gives control to PHP layer. PHP then set up an environment to execute the PHP page requested. In turn it also create a symbol table which will store various variables being used while executing this page.
    • PHP then calls the RINIT method of each module. RINIT refers to Request Initialization Module. Classic example of RINIT module implementation is the Session’s module. If enabled in php.ini, the RINIT method of Sessions module will pre-populate the $_SESSION variable and save in the symbol table.
    • RINIT method can be thought as an auto_prepend_file directive, which is pre-appended to every PHP script before execution.
  • More on RINIT ...
    • A typical RINIT method looks like:
    • PHP_RINIT_FUNCTION(extension_name) {
    • /* Initialize session variables, pre-populate variables, redefine global variables etc */
    • }
  • PHP Shutdown ...
    • After the page execution is complete either by reaching the end of the script or by call of any exit() or die() function, PHP starts the cleanup process. In turn it calls RSHUTDOWN method of every extension. RSHUTDOWN can be thought as auto_append_file directive to every PHP script, which no matter what happens, is always executed.
    • RSHUTDOWN method, destroys the symbols table (memory management) by calling unset() on all variables in the symbols table
  • More on shutdown ...
    • A typical RSHUTDOWN method looks like:
    • PHP_RSHUTDOWN_FUNCTION(extension_name) {
    • /* Do memory management, unset all variables used in the last PHP call etc */
    • }
  • More on shut down ...
    • Finally when all requests has been made and SAPI is ready to shutdown, PHP call its 2nd step of shutdown process.
    • PHP calls the MSHUTDOWN method of every extension, which is basically the last chance for every extension to unregister handlers and free any persistent memory allocated during the MINIT cycle.
    • And that brings us to the end of what we can call as PHP Lifecycle. Important point to note is that Step 1 of Startup and Step 2 of Shutdown happens when no request is being made to the web servers.8. Finally Zend Engine returns back the result to PHP Core, which gives that to SAPI layer, and finally which displays it on your browser.
  • It's Finish now ...
    • Mail me if you have any query .. [email_address]