Sunday, January 29, 2017

Web Architecture with PHP

Web Architecture with PHP


Web Architecture Diagram of PHP Applications


Now lets put all these together and see how do they work actually. An Architecture Diagram is a logical diagram that shows how each of the components in a system is connected with each other and how are the data flowing between. If we draw architecture diagram for a typical PHP based web application it will be like the below diagram.

  • First user accessed the website through browser. That means user types the URL of the website in browser and hit go.
  • The page request on browser will reach to the Web Server (Apache).
  • Web server will collect that requested page (HTML or PHP or Image file etc) from its document root. (In our example it will be www folder in WAMP. You will see it in next one) 
  • Now if it is a static element like HTML , CSS , image file or Java Script file then Apache will send it directly to browser.
  • And Browser will render it to user on screen
  • If it is a PHP file then Apache sends the content of the file to PHP Interpreter. PHP interpreter interprets the PHP code and executes it. if DB operation is required it performs the same (E)
  • PHP Interpreter generates output (if the PHP code is to generate any output) and sends to Apache
  • Apache sends that content to browser
  • Browser renders it to users' screen
All static components like HTML, CSS files ,Image Files , Java Scripts etc doesn't need interpreter. Our web browsers are built to render them and display on screen properly. That is why if user requests for these kind of components Apache collects them from Document root and sends back to Browser directly.

Only if requested page is a PHP page Apache will send it to PHP interpreter to get it translated and executed.

That is why though those listed static components reside on Server we will consider them as part of User Interface and as they get rendered at user's browser we may refer them as Client side components. In web technology Browsers are Client terminals.

And for similar reason we will refer PHP files as Server side components as they have dependencies on another Server Side component PHP Interpreter and cannot be executed only on browsers.

Now let me explain the keywords of the definition as you will be able to understand them better
1. PHP files are kept on Server (in Document root)  - Server Side
2. PHP Interpreter interprets PHP language and executes instructions as per code.It does not need compilation

PHP Life Cycle


Here is what happens at backend :

We never start any PHP daemon or anything by ourself. When we start Apache, it starts the PHP interpreter along itself PHP is linked to Apache (In general term SAPI i.e. a Server API) using mod_php5.so module PHP as a whole consists of 3 modules (Core PHP, Zend Engine and Extension Layer) Core PHP is the module which handles the requests, file streams, error handling and other such operations 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.

Extensions are a bunch of functions, classes, streams made available to the PHP scripts, which can be used to perform certain tasks. For example, we need mysql extension to connect to MySQL database using PHP.

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.

Finally Zend Engine returns back the result to PHP Core, which gives that to SAPI layer, and finally which displays it on your browser.

A Step Deeper

But wait! This is still not over yet. Above was just a high level flow diagram. Lets dig a step deeper and see what more is happening behind the scenes:

1. When we start Apache, it also starts PHP interpreter along itself 
2. PHP startup happens in 2 steps
3. 1st step is to perform initial setup of structures and values that persists for the life of SAPI
4. 2nd step is for transient settings that only last for a single page request

Step 1 of PHP Startup

Confused over what’s step 1 and 2 ? No worries, next we will discuss the same in a bit more detail. Lets first see step 1, which is basically the main stuff.
Remember step 1 happens even before any page request is being made.

1. As we start Apache, it starts PHP interpreter
2. PHP calls MINIT method of each extension, which is being enabled. View your 3. php.ini file to see the modules which are being enabled by default
4. 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

A typical MINIT method looks like:

      PHP_MINIT_FUNCTION(extension_name) {

          /* Initialize functions, classes etc */

      }

Step 2 of PHP Startup

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.

A typical RINIT method looks like:

      PHP_RINIT_FUNCTION(extension_name) {

          /* Initialize session variables, pre-populate variables, redefine global variables etc */

      }

Step 1 of PHP Shutdown

Just like PHP startup, shutdown also happens in 2 steps.

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

A typical RSHUTDOWN method looks like:

      PHP_RSHUTDOWN_FUNCTION(extension_name) {

          /* Do memory management, unset all variables used in the last PHP call etc */

      }

Step 2 of PHP Shutdown

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.

A typical RSHUTDOWN method looks like:

      PHP_MSHUTDOWN_FUNCTION(extension_name) {

          /* Free handlers and persistent memory etc */

      }


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.

Saturday, January 26, 2013

Valentine's Day Keywords and Banners

Valentine's Day Keywords and Banners

















  1. HAPPY VALENTINES DAY
  2. FRED ON VALENTINES DAY
  3. VALENTINES DAY
  4. GIFT IDEAS
  5. GIFT SHOPS
  6. VALENTINE CARDS
  7. VALENTINES DAY SAYINGS
  8. VALENTINE HEARTS
  9. VALENTINES DAY CARDS
  10. LINDT CHOCOLATE
  11. GIFTS FOR MEN
  12. CHOCOLATE RECIPES
  13. CHOCOLATE TRUFFLES
  14. CHOCOLATE COINS
  15. GIFTS FOR HER
  16. DARK CHOCOLATE
  17. GIFTS FOR HIM
  18. VALENTINES DAY HISTORY
  19. BELGIAN CHOCOLATE
  20. VALENTINES CARDS
  21. VALENTINES DAY GIFTS
  22. V DAY
  23. VALENTINE DAY
  24. GHIRARDELLI CHOCOLATE
  25. VALENTINES DAY GIFTS FOR HIM
  26. VALENTINE CARD
  27. CHEAP GIFTS
  28. CHOCOLATE FUDGE
  29. VALENTINE CANDY
  30. GIFT IDEAS FOR MEN
  31. CHOCOLATE BARS
  32. GIFT IDEAS FOR HER
  33. MONOGRAMMED GIFTS
  34. ROMANTIC GIFTS
  35. VALENTINES DAY GIFTS FOR MEN
  36. VALENTINES CARD
  37. NOVELTY GIFTS
  38. CHOCOLATE RECIPE
  39. UNIQUE GIFTS
  40. HOLIDAY GIFT IDEAS
  41. FLORAL ARRANGEMENTS
  42. GIFT BASKET IDEAS
  43. VALENTINES DAY DECORATIONS
  44. SWISS CHOCOLATE
  45. UNIQUE GIFT IDEAS
  46. CHOCOLATE FOUNTAINS
  47. VALENTINES GIFTS FOR HIM
  48. GIFT IDEAS FOR HIM
  49. GIFTS FOR KIDS
  50. INSPIRATIONAL GIFTS
  51. VALENTINES GIFTS
  52. MILK CHOCOLATE
  53. VALENTINES DAY CARD
  54. CHOCOLATE PRETZELS
  55. COOL GIFTS
  56. GIFTS FOR GUYS
  57. BOYFRIEND GIFT IDEAS
  58. HANDMADE GIFTS
  59. HOLIDAY GIFT IDEA
  60. VALENTINE ROSES
  61. VALENTINES DAY CANDY
  62. UNIQUE GIFT IDEA
  63. VALENTINES GIFTS FOR MEN
  64. GIRLFRIEND GIFT IDEAS
  65. CREATIVE GIFTS
  66. MENS GIFTS
  67. COOL GIFT IDEAS
  68. FLOWERS WHOLESALE
  69. VALENTINES DAY GIFTS FOR GUYS
  70. CHOCOLATE FAVORS
  71. CHOCOLATE MAKING
  72. VALENTINES CANDY
  73. SUGAR FREE CHOCOLATE
  74. ST VALENTINES DAY
  75. CREATIVE GIFT IDEAS
  76. BEST CHOCOLATE
  77. BULK CHOCOLATE
  78. GREAT GIFT IDEAS
  79. GIFTS WHOLESALE
  80. FRENCH CHOCOLATE
  81. VALENTINE CHOCOLATES
  82. CHEAP GIFT IDEAS
  83. PERSONALIZED GIFTS FOR KIDS
  84. VALENTINE CHOCOLATE
  85. FUN GIFTS
  86. UNIQUE GIFTS FOR WOMEN

Saturday, November 17, 2012

New Year 2013 Keywords and Images

New Year 2013 Keywords and Images


























new years greetings
new years greeting cards
new year wishes messages
new year wishes quotes
free new year cards
happy new year cards
happy new year ecards
new years cards
new years photo cards
happy new year wishes messages
greeting for new year
new years card
happy new year ecard
happy new year greeting cards
new year greetings message
new years ecards
happy new year card
free happy new year cards
new year greeting cards
free new year greeting cards
happy new year e cards
new years greeting
free new years ecards
happy new year wishes sms
new year ecard
new year ecards
free new year ecards
chinese new year ecard
new year card messages
new year celebrations
new year wishes greetings
free new year greetings
new year e cards
new year card message
happy new year cards free
greeting cards for new year
happy new year 2013 images
free ecards new year
123 greetings new year
greetings for new year
ecard new year
new year ecards free
new year greetings cards
ecards new year
123 greetings
new year messages for friends
new year greetings card
greeting cards new year
new year wishes greeting cards
happy new years ecard
card new year happy new year
 free happy new year e cards
 happy new years e cards
 happy new years wish quotes
 happy new year messages sms
 happy new years cards free
 free cards happy new year
 happy new years greeting cards
 free ecards happy new year 2013
 happy new year card ideas
 best happy new year card
 greeting cards for happy new year
 send happy new year card
 free happy new year wishes
 happy new years 2013 cards
 best happy new year cards
 happy new year 2013 free cards
 free happy new year e card
 happy new years wishes funny
 happy new year text message 2013
 e card happy new year free
 greeting for happy new years
 a happy new year card
 happy new years wishes 2013
 free greeting cards happy new year
 happy new years cards 2013
 happy new year free greeting cards
 happy new year free e-card
 happy new year online cards
 quotes about happy new year wish
 happy new year wishes for family
 wishing a happy new year message
 cool happy new year sms
 good happy new year quotes
 happy new year electronic cards
 happy new year sms greetings
 happy new years quotes 2013
 good happy new year messages
 great happy new year quotes
 happy new year s cards
 quotes of happy new year wishes
 free card happy new year 2013
 greeting card for happy new year
 cool happy new year message
 happy new years 2013 quotes
 free happy new year card 2013
 happy new year wishes and quotes


Saturday, October 13, 2012

Facebook Cover Pictures