How to make a PHP extension

Blog: http://lijinhuan.blog.51cto.com/

Weibo: http://weibo.com/lijinhuaExperience

Code: https : //github.com/lijinhuan

First, install php

, if PHP is installed / USR / local / PHP

Second, PHP Extension Frame Tool

Enter / PHP Source / EXT Directory

Execute

./ext_skel –extname = MY_MODULE

Display result

Creating Basic Files: config.m4 config.w32.svnignore my_module.c php_my_module.h Credits Experimental Tests / 001.phpt my_module.php [DONE].

TO Use Your New Extension, You Will Have to Execute The Following Steps:

1. $ CD ..

2. $ VI EXT / MY_MODULE / Config.m4

3. $ ./Buildconf

4. $ ./Configure – [with | enable] -my_module

5. $ Make

6. $………………………. ..

Repeat Steps 3-6 Until You Are Satisfied with ext / my_module / config.m4 and

Step 6 confirms That Your Module Is Compiled INTO PHP. THEN, START WRITING

In fact, how do you do it here

in the current directory Perform CD MY_MODULE / Enter Our Module Directory

Then we want to modify the file order is

configue.m4

MY_MODULE.C

PHP_MY_MODULE.H

Modify configue.m4

According to your own choice will be

DNL PHP_ARG_WITH (my_module, for my_module support,

DNL Make Sure That The Comment IS Aligned:

DNL [–WITH-MY_MODULE INCLUDE MY_MODULE SUPPort])

Modified to

php_arg_with (my_module, for my_module support,

MAKE Sure That The Comment IS Aligned:

[–With-my_module in cd )_module support])

DNL PHP_ARG_ENABLE ( MY_MODULE, WHETHER TO ENABLE MY_MODULE Support,

DNL Make Sure That The Comment IS ALIGNED:

DNL [–Nable-my_module enable my_module support])

Modified to

PHP_ARG_ENABLE (My_Module, WHETHER TOEABLE MY_MODULE Support,

Make Sure That the Comment is aligned:

[–Nable-my_module enable my_module support])

is actually removed Previous DNL

Modify My_Module.c

/ * ENTRY IN MY_MODULE_FUNCTIONS

/ * ENTRY IN MODULE MUSIT HAVE

* /

FUNCTION_ENTRY MY_MODULE_FUNCTIONS [] = {

php_fe (Say_Hello, NULL) / *? Add a line Code * /

PHP_FE (CONFIRM_MY_MODULE_COMPILED, NULL) / * for Testing, Remove Later. * /

{ NULL, NULL, NULL} / * must be the last line in my_module_functions [] * /

};

At the end of the file, the following code is added

{

{

zend_printf (“Hello WORLD / N”);

}

Modify php_my_module.h

in PHP_FUNCTION (CONFIRM_MY_MODULE_COMPILED); / * for Testing, Remove Later. * /

Add a line:

PHP_Function (Say_Hello); / * for testing, remove later. * /

Third, execution

/ USR / Local / PHP / BIN / PHPIZE

Fourth, compilation and installation expansion

and then execute ./configure –enable-my_module – WITH-PHP-Config = / usr / local / php / bin / php-config

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment