Use C to develop PHP extension instances (Basic edition)

Source: Internet
Author: User
Step 1: Create an extension skeleton. The [html] cd/usr/local/src/php-5.3.6/ext /. /ext_skel -- extname = laiwenhuicd/usr/local/src/php-5.3.6/ext /. /ext_skel -- extname = laiwenhui Step 2: modify the compilation parameters. [Html] v

Step 1: Create an extension skeleton.
[Html]
Cd/usr/local/src/php-5.3.6/ext/
./Ext_skel -- extname = laiwenhui

Cd/usr/local/src/php-5.3.6/ext/
./Ext_skel -- extname = laiwenhui Step 2: modify the compilation parameters.
[Html] view plaincopyprint? Cd php-5.3.6/ext/laiwenhui
Vi config. m4

Cd php-5.3.6/ext/laiwenhui
Remove vi config. m4
PHP_ARG_ENABLE (laiwenhui, whether to enable laiwenhui support,
[-- Enable-laiwenhui Enable laiwenhui support])
Dnl before two rows
After modification:
Dnl Otherwise use enable:
PHP_ARG_ENABLE (laiwenhui, whether to enable laiwenhui support,
Dnl Make sure that the comment is aligned:
[-- Enable-laiwenhui Enable laiwenhui support])


Step 3: write code
[Html]
Vim php_laiwenhui.h

Vim php_laiwenhui.h
In

PHP_FUNCTION (confirm_laiwenhui_compiled );

Add a line later

PHP_FUNCTION (test );

[Html]
Vim laiwenhui. c

Vim laiwenhui. c

In

PHP_FE (confirm_laiwenhui_compiled, NULL)

Add
PHP_FE (test, NULL)


** Add the following code at the end of the file :**
[Html]
PHP_FUNCTION (test)
{
Char * arg = "This is my first extention! ";
Int len;
Char * strg;
 
Len = spprintf (& strg, 0, "% s \ n", arg );
RETURN_STRINGL (strg, len, 0 );
}

PHP_FUNCTION (test)
{
Char * arg = "This is my first extention! ";
Int len;
Char * strg;

Len = spprintf (& strg, 0, "% s \ n", arg );
RETURN_STRINGL (strg, len, 0 );
} Step 4: compile the code
[Html]
/Usr/local/php/bin/phpize
./Configure -- with-php-config =/usr/local/php/bin/php-config
Make
Make install

/Usr/local/php/bin/phpize
./Configure -- with-php-config =/usr/local/php/bin/php-config
Make
Make install
My PHP installation path is/usr/local/php
This will generate a file/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/laiwenhui. so

Edit the PHP configuration file php. ini and add extensions:
[Html]
Vim php. ini

Vim php. ini added in the [PHP] module:
[Html]
Extension = laiwenhui. so

Extension = laiwenhui. so modify extension_dir in the php. ini file to this directory:
[Html]
Extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613 /"

Extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613 /"


Step 5: check the installation result

1. restart php-fpm, ngixn
2./use/local/php/bin/php-m
Check whether the laiwenhui extension exists.


Step 6: execute the test code


Create test. php in the root directory of the website
Vim test. php
The code is as follows:
Echo test ();

The result is:
This is my first extention!

If you can successfully complete the above steps, congratulations on completing the first extension.

 

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.