PHP How to call C interface Error-free version _php tutorial

Source: Internet
Author: User

PHP How to call C interface Error-free version


1. First of all, to install PHP

2. Enter the ext directory under the download directory of PHP

#cd/root/php-5.3.6/ext

#./ext_skel--EXTNAME=HMC

Description

./ext_skel--extname=module_name
Module_name is the name of the extension module that you can choose, such as the HMC I chose. Executing the tool will automatically create your chosen module_name name in the EXT directory, which has generated the relevant code, the code only need to adjust the Config.m4 file three lines of comments can be normal to compile with this custom extension PHP.

3. Modify CONFIG.M4

You can copy the generated module directory to any place you wish to place it.

Go to the HMC directory

VI CONFIG.M4

Open a CONFIG.M4 file using a text editor

Depending on your own choice, you will

DNL Php_arg_with (HMC, for HMC support,

DNL Make sure, the comment is aligned:

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

Modified into

Php_arg_with (HMC for HMC support,

Make sure, the comment is aligned:

[--WITH-HMC Include HMC support])

or the

DNL php_arg_enable (HMC, whether to ENABLE HMC support,

DNL Make sure, the comment is aligned:

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

Modified into

Php_arg_enable (HMC, whether to ENABLE HMC support,

Make sure, the 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

Vi HMC.C

Modify the following code in the file

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

*/

Const Zend_function_entry hmc_functions[] = {

Php_fe (Say_hello, NULL)/* Adds 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 world\n");

}

Save File Exit



VI php_hmc.h

Php_function (confirm_hmc_compiled) in the file, add the following code in front of the line

Php_function (Say_hello);

Save File Exit

5. Compiling the installation

#phpize
#./configure--ENABLE-HMC

#make

#make Install

Should have a hmc.so file in PHP's modules directory, different machine locations will not be the same

6. Modify the PHP configuration

Edit the php.ini and add the extension:
Added under [PHP] module:
Extension = hmc.so
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. Commissioning

You can enter it at the command line

#php –q c.php

Need to enter the current WWW directory

Check to see if the module is 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

#/usr/bin/php-m

9. Functions with Parameters

Vi HMC.C

Modify the last Say_hello function to read as follows:

Php_function (Say_hello)
{
Zval **yourname;
if (Zend_num_args ()! = 1 | | zend_get_parameters_ex (1, &yourname) = = FAILURE)

{
Wrong_param_count;
}
zend_printf ("Hello World,%s\n", Z_strval_pp (yourname));
}


Modify c.php to

Say_hello ("Qingqing Moon");
?>

http://www.bkjia.com/PHPjc/953964.html www.bkjia.com true http://www.bkjia.com/PHPjc/953964.html techarticle PHP How to call the C interface error-free version 1. First of all, to install PHP 2. Enter the ext directory under the download directory of PHP #cd/root/php-5.3.6/ext #./ext_skel--EXTNAME=HMC Description:./ext_skel- -...

  • Related Article

    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.