PHP underlying implementation

Source: Internet
Author: User
Tags zts
PHP underlying implementation?


2. compile PHP in the local environment. required versions: 5.4, 5.5, and 5.6. each version must contain three compiling versions, including

/Usr/lib/apache2/modules


/Etc/apache2/mod-enabled/

Vim php5.load



. Compile the ztf, ntf, and debug modes of php.

A. install the apsx tool apt-get install apache-dev

B. run in the php source package. /configure -- prefix =/home/merlin/make_php_version/php-5.4-zts-debug/-- enable-maintainer-zts -- with-apxs2 =/usr/bin/apxs2 -- enable-debug

C. make & make install generate the libphp5.so file under/usrb/apache2/modules

D. add the module file. so to php5.load under/etc/apache2/mod-enabled.


An error occurred while compiling. undefined reference to 'libiconv _ open'



Configuration File:

Find php. ini. development in the installation package and copy it to the lib in the installed directory.

Specify the directory for each php execution of this version.

Examples:/home/merlin/php_version/php-5.5.21-zts-debug/bin/php-I | grep php. ini


Solution:
# Wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
# Tar-zxvf libiconv-1.13.1.tar.gz
# Cd libiconv-1.13.1
#./Configure -- prefix =/usr/local/libiconv
# Make
# Make install


Check php again and specify the iconv location -- with-iconv =/usr/local/libiconv



3. compile a simple PHP extension to implement three PHP methods, receive parameters respectively, and complete the result output:

A. for numbers a and B, add, subtract, multiply, and divide

B. number of repetitions of string a in string B

C. intersection and difference set of array a and array B


Reference http://www.laruence.com/2009/04/28/719.html


Source code package execution

  1. ./Ext_skel -- extname = myfunctions -- proto = myfunctions. def


Make clean & make install

/Etc/php5 operate ini and move so files


Type specifier Corresponding C type Description
L Long Symbol integer
D Double Floating point number
S Char *, int Binary string, length
B Zend_bool Logical type (1 or 0)
R Zval * Resources (file pointers, database connections, etc)
A Zval * Union array
O Zval * Any type of object
O Zval * Specifies the type of object. Class type of the target object
Z Zval * No zval for any operation

If (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC, "sdd", & str, & str_len, & a, & B) = FAILURE ){

Return;

}



Set the return value and end the function Set return value Macro return type and parameters
RETURN_LONG (l) RETVAL_LONG (l) Integer
RETURN_BOOL (B) RETVAL_BOOL (B) Boolean (1 or 0)
RETURN_NULL () RETVAL_NULL () NULL
RETURN_DOUBLE (d) RETVAL_DOUBLE (d) Floating point number
RETURN_STRING (s, dup) RETVAL_STRING (s, dup) String. If dup is 1, the engine will call estrdup () to duplicate s and use copy. If dup is 0, s is used.
RETURN_STRINGL (s, l, dup) RETVAL_STRINGL (s, l, dup) String value with a length of l. Similar to the previous macro, but the speed is faster because the length of s is specified.
RETURN_TRUE RETVAL_TRUE Returns a boolean value of true. Note that this macro has no parentheses.
RETURN_FALSE RETVAL_FALSE Returns a boolean value of false. Note that this macro has no parentheses.
RETURN_RESOURCE (r) RETVAL_RESOURCE (r) Resource handle.



Php-I | grep php. ini

1. describe the PHP operating mechanism in detail (depending on your mood );

PHP is a layer-4 system from bottom to top:

  • Zend Engine: Zend is implemented in pure C and is the kernel part of PHP. it translates PHP code (lexical, syntax parsing, and other compilation processes) it can process and implement corresponding processing methods, implement basic data structures (such as hashtable and oo), allocate and manage memory, and provide corresponding api methods for external calls, is the core of everything, and all peripheral functions are implemented around Zend.
  • Extensions: Around the Zend Engine, extensions provides various basic services in a component-based manner. our common built-in functions (such as the array series) and standard libraries are implemented through extension, you can also implement your own extension as needed to achieve function expansion and performance optimization (for example, the PHP middle layer being used by the Post Bar and rich text parsing are typical applications of extension ).
  • Sapi: the full name of Sapi is Server Application Programming Interface, that is, the Server Application Programming Interface. Sapi enables PHP to interact with peripheral data through a series of hook functions, this is a very elegant and successful PHP design. through sapi, PHP itself is successfully decoupled from upper-layer applications. PHP can no longer consider how to be compatible with different applications, applications can also implement different processing methods based on their own characteristics.
  • Upper-layer applications: this is the PHP program we usually write and various application modes are obtained through different sapi methods, for example, you can use webserver to implement web applications and run them in script mode under the command line.

  • Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

    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.