How PHP invokes the C interface without the wrong version

Source: Internet
Author: User
Tags command line config php file php download save file

1. The first is to install a good PHP

2. Into the PHP download extract directory under the EXT directory




Module_name is the name of the extension module that you can choose from, such as the HMC I chose. After executing the tool will automatically in the EXT directory to create your choice of module_name name directory, which has generated the relevant code, which only need to adjust the Config.m4 file in the three lines of comments can normally compile with this custom extension module PHP.

3. Modify CONFIG.M4

You can copy the generated module directory to any desired place

Access to the HMC directory


To open a CONFIG.M4 file using a text editor

According to your own choice, you will

DNL Php_arg_with (HMC, for HMC support,

DNL Make sure this comment is aligned:

DNL [--WITH-HMC Include HMC support])

Modified into

Php_arg_with (HMC for HMC support,

Make sure this comment is aligned:

[--WITH-HMC Include HMC support])

or to

DNL php_arg_enable (HMC, whether to ENABLE HMC support,

DNL Make sure this comment is aligned:

DNL [--ENABLE-HMC enable HMC support])

Modified into

Php_arg_enable (HMC, whether to ENABLE HMC support,

Make sure this comment is aligned:

[--ENABLE-HMC enable HMC support])

Generally I will choose the latter and then save the exit.

4. Modify the. C and. h file codes


Modify the following code in the file

/* Every user visible function must have a entry in hmc_functions[].


Const Zend_function_entry hmc_functions[] = {

Php_fe (Say_hello, NULL)/* Add a line of code * *

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

{null, NULL, NULL}/* must is the last line in hmc_functions[] * *


Add the following code at the end of the file

Php_function (Say_hello)


zend_printf ("Hello worldn");


Save File Exit

VI php_hmc.h

Php_function (confirm_hmc_compiled) in a file, add the following code before a line

Php_function (Say_hello);

Save File Exit

5. Compile and install



#make Install

There should be a file in the PHP modules directory, and different machine locations will not be the same

6. Modify PHP Configuration

Edit the php.ini and add the extensions:
Add under [PHP] module:
Extension =
Restart httpd

#service httpd Restart

7.php Call

Create a c.php file in the corresponding WWW directory

Say_hello ();

The browser should then output:

Hello World

8. Debugging

You can enter at the command line

#php –q c.php

Need to enter the current WWW directory

Check to see if the modules are installed with Phpinfo ().

You can also apply the PHP-M command

First Use

#which PHP

Find PHP directory, different machine directory is not the same


9. Functions with Parameters


Modify the last Say_hello function as follows:

Php_function (Say_hello)
Zval **yourname;
if (Zend_num_args ()!= 1 | | | ZEND_GET_PARAMETERS_EX (1, &yourname) = = failure)

zend_printf ("Hello World,%sn", Z_strval_pp (yourname));

Modify c.php to

Say_hello ("Qingqing Moon Son");

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.