PHP Learning Series-Source directory structure Learning ____php

Source: Internet
Author: User
Tags php language sapi zend

Through the study of the previous article, we have a general understanding of PHP knowledge, such as PHP is open source, free, suitable for web development of the service-side scripting language, suitable for web site development, PHP is an interpreted language, by the Zend Engine for the interpretation of the PHP language. In this article, we will continue to study the contents of the previous article and learn more about ZEND,ISAPI and PHP extensions by looking at the source structure of the PHP language.

PHP source Download Address: Download Select a version of the download can be. The PHP source structure is shown below.


Directory Structure Analysis:

/    : Mainly contains some documentation and design plan.
The implementation directory of the Zend:zend engine. This includes lexical parsing, OPCODE, and the language runtime environment.
TSRM: Thread-safe resource manager.
Build: Place some files related to the source code compilation.
ext  : Official extended directory. Including array series, PDO series, SPL series and other functions of the implementation.
main: The core of the file, the implementation of the basic PHP infrastructure.
pear:php extension and application warehouse.
SAPI: Code for various server abstraction layers. such as Apache mod_php,cgi,fastcgi and FPM and so on interface.
tests:php A collection of test scripts.
the script directory under Scripts:linux.
some implementations related to the Win32:windows platform.

Here to focus on Zend, ext, SAPI three directories. Zend

Here's a bit more about what the Zend engine is and what role it plays in the PHP language.

Zend engine function

Advance precompilation (Compile), and then execute (execute).

(1) Lexical analysis: The code cut into a mark Toekn.

(2) grammar Analysis (Parser): grammar check.

(3) Generate opcode (opcode): The Zend engine compiles these Token, compiles the code to opcode, and binds the corresponding parameters, and function calls.

(4) Execute (EXECUTE): The Zend engine executes these opcode.

(5) Memory management

It can be said that Zend is the heart of PHP, is it to ensure that PHP can be stable and efficient operation. ext

The previous version of PHP 3.0, the code coupling is too strong, causing the expansion is very difficult, after the PHP 3.0 version of the PHP function is split, some of the functions by the corresponding expansion to achieve.

With this folder open, we can see multiple extensions such as PDO, MySQL, curl, DOM, date, and so on. This architecture of PHP extensions greatly reduces the developer's development costs and increases the flexibility of the expansion. For example, if we want to use the MySQL service via PHP, we need only the functions provided by MySQL. As to how the MySQL extension internally communicates with the MySQL service via socket communication and interacts with it, we don't have to worry about it, it's easy.

As for the extension of the addition and expansion of the Windows/linux platform differences, the previous article has been said, no longer tired. SAPI

Sapi:server application Programming Interface, Server-side application programming port. We've already said how PHP is executed, and how PHP is accessed and told to be executed. Yes, SAPI is the role.

The common calling SAPI method has the following four kinds:

(1) mod_php5:php module for Apache.

(2) Cgi:fork-and-execute.

(3) Fastcgi: Resident (long-live) type of CGI.

(4) cli:php command line mode.

Big points, the above four modes can be divided into two categories: Web server forwarding mode, command line mode

Tertiary belongs to the Web server forwarding mode, and the fourth mode belongs to the command line mode.

Subdivide, four modes can split three kinds: Extended mode, CGI mode, CLI mode

The first one belongs to the extended mode. The Apache server expands the PHP module, and when the Apache server receives the. PHP type of request, the request is distributed to the mod_php module, which, in general, does not apply to high concurrency (as for why it will not be perfect later), but the processing efficiency is still possible.

The second to third type belongs to the CGI pattern. At this time, when Nginx, LIGHTTPD and other Web servers receive the. php file request, the request is distributed through the CGI interface to the Zend to parse and eventually return. This model is widely used at present.

The third type belongs to the CLI mode. As the name suggests, you can execute the. php file at the command line, which does not require the forwarding of the Web server. At present, this model is limited in many places and is not widely used.

OK, finally attach a PHP architecture diagram


Reference article: Zend Engine & PHP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.