PHP Bottom-up implementation

Source: Internet
Author: User
Tags sapi zts
?


2, please in the local environment, compile PHP, requirements: Version 5.4, 5.5, 5.6, each version to cover 3 compiled version, including NTS \ ZTS \ Debug

/usr/lib/apache2/modules


/etc/apache2/mods-enabled/

Vim Php5.load



. Compiling PHP's Ztf,ntf,debug mode

A. Installing the APSX tool Apt-get install Apache-dev

B. Run under 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 libphp5.so file under/usrb/apache2/modules

D. Add the module file under/etc/apache2/mods-enabled php5.load. So


Compile error resolution undefined reference to ' Libiconv_open '



Configuration file:

Locate the php.ini.development copy in the installation package to Lib in the post-installation directory

Each time you execute this version of PHP to specify a directory

Example:/home/merlin/php_version/php-5.5.21-zts-debug/bin/php-i|grep php.ini


Workaround:
#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 to specify the location of the Iconv--with-iconv=/usr/local/libiconv



3, write a simple PHP extension, implement 3 PHP methods, receive parameters, and complete the output of the results:

A. Number A and number B, plus, minus, multiply, divide

B. String A, number of repetitions 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 Package Execution

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


Make clean && make && make install

/ETC/PHP5 operating ini and moving so files


Type specifier The corresponding C type Describe
L Long Symbol integer
D Double Floating point number
S char *, int binary string, length
B Zend_bool Logic type (1 or 0)
R Zval * Resources (file pointers, database connections, etc.)
A Zval * Union array
O Zval * Any type of object
O Zval * An object of the specified type. The class type of the target object needs to be provided
Z Zval * Zval without any action

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 the return value Macro return types and parameters
Return_long (L) Retval_long (L) Integer
Return_bool (b) Retval_bool (b) Boolean number (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 the DUP is 1, the engine calls Estrdup () to repeat S, using the copy. If the DUP is 0, use s
Return_stringl (S, L, DUP) Retval_stringl (S, L, DUP) String value of length L. As with the previous macro, but because the length of s is specified, it is faster.
Return_true Retval_true Returns a Boolean value of true. Notice that the macro has no parentheses.
Return_false Retval_false Returns a Boolean value of false. Notice that the macro has no parentheses.
Return_resource (R) Retval_resource (R) The resource handle.



Php-i | grep php.ini

1, please specify the operating mechanism of PHP (thin to how deep to see your mood, ah);

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

  • Zend Engine: Zend as a whole with pure C implementation, is the core part of PHP, it will be PHP code translation (lexical, parsing and so on a series of compilation process) for the execution of opcode processing and implementation of the corresponding processing methods, the implementation of basic data structures (such as Hashtable, OO), Memory allocation and management, providing the corresponding API method for external invocation, is the core of all, all the peripheral functions are around Zend implementation.
  • Extensions: Around the Zend Engine, Extensions provides a variety of basic services through a component-based approach, and our common set of built-in functions (such as the array series), standard libraries, etc. are implemented through extension. Users can also implement their own extension to achieve functional expansion, performance optimization and other purposes (such as paste in the PHP middle layer, Rich text parsing is the typical application of extension).
  • SAPI:SAPI full name is the server application programming Interface, that is, the service-side application programming interface, SAPI through a series of hook functions, so that PHP can interact with the peripheral data, which is a very elegant and successful PHP design, By SAPI successfully decoupling PHP itself from the upper-layer application, PHP can no longer consider how to implement compatibility for different applications, and the application itself can be handled differently for its own characteristics.
  • Upper application: This is the PHP program we usually write, through different sapi ways to get a variety of application patterns, such as the implementation of Web applications through webserver, the command line to run scripts, and so on.

  • Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

  • 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.