A probe into PHP extensions

Source: Internet
Author: User

1. First build the extended framework structure

Cd/alidata/tmp/php-5.6.23/ext

./ext_skel--extname=myext--proto=myext.fun

1) The relevant file is generated at this time

Configure config.h include myext.c config.m4

2) main modification Files

Config.m4

Php_arg_with (Myext, for myext support,

Make sure, the comment is aligned:

[--with-myext Include Myext support])

DNL Otherwise Use enable:

Php_arg_enable (Myext, whether to ENABLE Myext support,

Make sure, the comment is aligned:

[--enable-myext enable myext support])

Myext.c

1) head File

#ifdef HAVE_CONFIG_H

#include "Config.h"

#endif

#include "Php.h"

#include "php_ini.h"

#include "ext/standard/info.h"

#include "Php_myext.h"

#include <stdio.h>

#include <malloc.h>// memory management calls

2) Variable Definition

static int le_myext;

3) defining Functions

Const Zend_function_entry myext_functions[] = {

Php_fe (Myext, NULL)/* For testing, remove later. */

Php_fe (Myext_fork,null)

Php_fe (Myext_list,null)

Php_pe (myext_insert,linklist* list, linklistnode* node, int pos)

Php_pe (myext_get,linklist* list, int pos)

Php_pe (myext_create,linklist*)

Php_pe (myext_destroy,linklist* list)

Php_fe_end/* Must be the last line in myext_functions[] */

};

4) Zend module definition

Zend_module_entry Myext_module_entry = {

Standard_module_header,

"Myext",

Myext_functions,// delegate load defined function @ identity

Php_minit (Myext),

Php_mshutdown (Myext),

Php_rinit (Myext),/* Replace with NULL If there's nothing to does at request start */

Php_rshutdown (Myext),/* Replace with NULL If there's nothing to does at request end */

Php_minfo (Myext),

Php_myext_version,

Standard_module_properties

};

5) Implementing an export function

Php_function (Myext_list)

{

Long lptr;

Double dptr;

if (Zend_parse_parameters (Zend_num_args () tsrmls_cc, "LD", &lptr, &dptr) = = FAILURE) {

Return

}

zend_printf ("Lptr value ad%ld", lptr);

zend_printf ("Dptr value ad%ld", dptr);

}

6) Accept user-passed parameters

6.1) Number of parameters obtained

Zend_num_args () tsrmls_cc//zend_api.h defined

6.2) Get entity Parameters

Defining Variables

Long lptr;

Double dptr;

if (Zend_parse_parameters (Zend_num_args () tsrmls_cc, "LD", &lptr, &dptr) = = FAILURE) {

Return

}

&lptr,: The parameter that is accepted

&dptr: The parameter that is accepted

parameter Printing

zend_printf ("Lptr value ad%ld", lptr);

zend_printf ("Dptr value ad%ld", dptr);

7) Complete export function implementation

Php_function (Myext_list)

{

Long lptr;

Double dptr;

if (Zend_parse_parameters (Zend_num_args () tsrmls_cc, "LD", &lptr, &dptr) = = FAILURE) {

Return

}

zend_printf ("Lptr value ad%ld", lptr);

zend_printf ("Dptr value ad%ld", dptr);

}

2. Editing Extensions

/alidata/server/php-5.6.23/bin/phpize Compression Extension

./configure--with-php-config=/alidata/server/php-5.6.23/bin/php-config compiling the installation extension

/alidata/server/php-5.6.23/bin/php-m shows the extensions that have been installed

3. Modify php.ini

[Xhprof]

Extension=xhprof.so

Xhprof.output_dir=/tmp

Extension=swoole.so

Extension=myext.so

Extension=php_list.so

4.php calls

<?php

Myext_list ()

?>


This article is from the Linux OPS blog, so be sure to keep this source http://2853725.blog.51cto.com/2843725/1948992

A probe into PHP extensions

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.