A preliminary introduction to PHP extended development experience sharing _php skills

Source: Internet
Author: User
Tags zts
Environment: PHP 5.2.14 CentOS 5.5

The first step: Build the expanded skeleton

CD Php-5.2.14/ext
./ext_skel–extname=laiwenhui

Step Two: Modify the compilation parameters

CD Php-5.2.14/ext/laiwenhui
VI CONFIG.M4

Remove

Php_arg_enable (Laiwenhui, whether to ENABLE Laiwenhui support,

[--enable-laiwenhui enable Laiwenhui support])

DNL in front of two lines

Modified to:
Copy Code code as follows:

DNL otherwise use enable:
Php_arg_enable (Laiwenhui, whether to ENABLE Laiwenhui support,
DNL Make sure this comment is aligned:
[--enable-laiwenhui enable Laiwenhui support])


Step Three: Write code

Vim php_laiwenhui.h

In Php_function (confirm_laiwenhui_compiled); Add a new line: php_function (test);

After adding:

Php_function (confirm_laiwenhui_compiled); /* For testing, remove later. */
Php_function (test);

And then

Vim LAIWENHUI.C

Add Php_fe (test, NULL) after Php_fe (confirm_laiwenhui_compiled, NULL)

After adding:
Copy Code code as follows:

Zend_function_entry laiwenhui_functions[] = {
Php_fe (confirm_laiwenhui_compiled, NULL)/* For testing, remove later. */
Php_fe (test, NULL)/* For testing, remove later. */
{null, NULL, NULL}/* must is the last line in laiwenhui_functions[] * *
};

Add the following code to the last side of the file:
Copy Code code as follows:

Php_function (Test)
{
Char *arg = "This is my A-extention!";
int Len;
Char *STRG;
Len = spprintf (&STRG, 0, "%s\n", Arg);
Return_stringl (STRG, Len, 0);
}

Fourth Step: compiling the Code
Copy Code code as follows:

CD Php-5.2.6/ext/laiwenhui
/opt/module/php/bin/phpize
./configure–with-php-config=/opt/module/php/bin/php-config
Make
Make install

My PHP installation path is:/opt/module/php
This time a file is generated/opt/module/php/lib/php/extensions/no-debug-non-zts-20060613/laiwenhui.so

Edit PHP profile php.ini, add extensions:

Vim php.ini

Add under [PHP] module: extension = laiwenhui.so

; Extension=php_zip.dll
Extension = laiwenhui.so

Modify the Extension_dir in the php.ini file to this directory:
Extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"

; Directory in which the loadable Extensions (modules) reside.
Extension_dir = "/opt/module/php/lib/php/extensions/no-debug-non-zts-20060613/"

Step Fifth: Check the installation results

1. Restart Apache or PHP-FPM
2./opt/module/php/bin/php-m see if there are any Laiwenhui extensions included.
Step Sixth: Execute the test code

Create test.php in the site root directory

Vim test.php

The code reads as follows

<?php
echo Test ();
?>

After execution The result is: this I-extention!

If you can successfully complete these steps, congratulate yourself on completing the first extension.

The above is a simple step to expand PHP, please refer to:

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.