SlideShare a Scribd company logo
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.
SOME FACTS -1  We never start any PHP daemon or anything by ourself. When we start Apache, it starts the PHP interpreter along itself...
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]

More Related Content

PPT
The Php Life Cycle
PDF
Understanding PHP memory
PDF
PHP 7 new engine
PDF
PDF
Quick tour of PHP from inside
PDF
PHP 7 OPCache extension review
PDF
Php extensions workshop
PDF
Php and threads ZTS
The Php Life Cycle
Understanding PHP memory
PHP 7 new engine
Quick tour of PHP from inside
PHP 7 OPCache extension review
Php extensions workshop
Php and threads ZTS

What's hot (20)

PDF
Php7 extensions workshop
PDF
PHP7 is coming
PDF
Mysqlnd, an unknown powerful PHP extension
ODP
Php in 2013 (Web-5 2013 conference)
PDF
PHP 7 performances from PHP 5
PDF
Profiling php5 to php7
PDF
SymfonyCon 2017 php7 performances
ODP
PHP5.5 is Here
PDF
Symfony live 2017_php7_performances
PDF
Php engine
ODP
PHP Tips for certification - OdW13
PDF
Building Custom PHP Extensions
PDF
PHP Internals and Virtual Machine
PDF
Understanding PHP objects
PDF
Key features PHP 5.3 - 5.6
PPTX
PHP 5.6 New and Deprecated Features
PPTX
Php’s guts
PPTX
Php.ppt
PPT
Hacking with hhvm
Php7 extensions workshop
PHP7 is coming
Mysqlnd, an unknown powerful PHP extension
Php in 2013 (Web-5 2013 conference)
PHP 7 performances from PHP 5
Profiling php5 to php7
SymfonyCon 2017 php7 performances
PHP5.5 is Here
Symfony live 2017_php7_performances
Php engine
PHP Tips for certification - OdW13
Building Custom PHP Extensions
PHP Internals and Virtual Machine
Understanding PHP objects
Key features PHP 5.3 - 5.6
PHP 5.6 New and Deprecated Features
Php’s guts
Php.ppt
Hacking with hhvm
Ad

Viewers also liked (13)

PPTX
Data members and member functions
PDF
PHP, Under The Hood - DPC
PDF
Being functional in PHP (PHPDay Italy 2016)
PPTX
Internet of Things With PHP
PPTX
PHP Optimization
PDF
PHP WTF
PPTX
Php internal architecture
PPTX
PPTX
Laravel Beginners Tutorial 1
PDF
[Community Open Camp] 給 PHP 開發者的 VS Code 指南
KEY
Php 101: PDO
PDF
LaravelConf Taiwan 2017 開幕
PDF
Route 路由控制
Data members and member functions
PHP, Under The Hood - DPC
Being functional in PHP (PHPDay Italy 2016)
Internet of Things With PHP
PHP Optimization
PHP WTF
Php internal architecture
Laravel Beginners Tutorial 1
[Community Open Camp] 給 PHP 開發者的 VS Code 指南
Php 101: PDO
LaravelConf Taiwan 2017 開幕
Route 路由控制
Ad

Similar to How PHP Works ? (20)

PDF
PHP unserialization vulnerabilities: What are we missing?
PPTX
Zend Framework Workshop
PDF
Getting Started with PHP Extensions
PPT
Microsoft TechDays 2011 - PHP on Windows
PPTX
PHP - Introduction.pptx
ODP
The why and how of moving to PHP 5.4/5.5
PDF
Security Meetup 22 октября. «PHP Unserialize Exploiting». Павел Топорков. Лаб...
PDF
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
ODP
The why and how of moving to php 5.4
PPTX
Listen afup 2010
ODP
Professional PHP: an open-source alternative for enterprise development [Antw...
PDF
Professional PHP: an open-source alternative for enterprise development [Kort...
PPTX
PhP Training Institute In Delhi
PDF
Top 7 Skills PHP Developer Must Have
PPTX
Listen and look at your PHP code
PHP unserialization vulnerabilities: What are we missing?
Zend Framework Workshop
Getting Started with PHP Extensions
Microsoft TechDays 2011 - PHP on Windows
PHP - Introduction.pptx
The why and how of moving to PHP 5.4/5.5
Security Meetup 22 октября. «PHP Unserialize Exploiting». Павел Топорков. Лаб...
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
The why and how of moving to php 5.4
Listen afup 2010
Professional PHP: an open-source alternative for enterprise development [Antw...
Professional PHP: an open-source alternative for enterprise development [Kort...
PhP Training Institute In Delhi
Top 7 Skills PHP Developer Must Have
Listen and look at your PHP code

More from Ravi Raj (8)

PDF
Time series data monitoring at 99acres.com
PPT
Web application security
PPT
Code Review
PPT
PHP Exception handler
PPT
Is it time to start using HTML 5
PPT
Character Encoding issue with PHP
PPT
Web Performance Tips
ODP
High Performance Web Sites
Time series data monitoring at 99acres.com
Web application security
Code Review
PHP Exception handler
Is it time to start using HTML 5
Character Encoding issue with PHP
Web Performance Tips
High Performance Web Sites

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Empathic Computing: Creating Shared Understanding
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Machine Learning_overview_presentation.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
Building Integrated photovoltaic BIPV_UPV.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
sap open course for s4hana steps from ECC to s4
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Chapter 3 Spatial Domain Image Processing.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Empathic Computing: Creating Shared Understanding
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Machine Learning_overview_presentation.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Mobile App Security Testing_ A Comprehensive Guide.pdf
Encapsulation_ Review paper, used for researhc scholars
Digital-Transformation-Roadmap-for-Companies.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing

How PHP Works ?

  • 1. How PHP works ? Ravi Raj
  • 2. 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/
  • 3. 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.
  • 4. SOME FACTS -1 We never start any PHP daemon or anything by ourself. When we start Apache, it starts the PHP interpreter along itself...
  • 5. SOME FACTS -2 PHP is linked to Apache (In general term SAPI i.e. a Server API) using mod_php5.so module...
  • 6. SOME FACTS -3 PHP as a whole consists of 3 modules (Core PHP, Zend Engine and Extension Layer)
  • 7. SOME FACTS -4 Core PHP is the module which handles the requests, file streams, error handling and other such operations
  • 8. 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.
  • 9. 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
  • 10. 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.
  • 11. Its Easy to understand !!! Right ?? OH!!! NO !!! … It's a overview only … Take a one more closer look now …
  • 12. 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
  • 13. STEP -2 A typical MINIT method looks like: PHP_MINIT_FUNCTION(extension_name) { /* Initialize functions, classes etc */ }
  • 14. 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.
  • 15. More on RINIT ... A typical RINIT method looks like: PHP_RINIT_FUNCTION(extension_name) { /* Initialize session variables, pre-populate variables, redefine global variables etc */ }
  • 16. 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
  • 17. 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 */ }
  • 18. 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.
  • 19. It's Finish now ... Mail me if you have any query .. [email_address]