This article requires the use of the WebService client program generated in the previous article. For details, see [url] http://commandos.blog.51cto.com/154976/130652#/url], but you only need to compile it into a dynamic or static Link Library. In this article, the main () in the WebService client program is renamed to testPhpModule (), and the string printed to the console is returned. After compilation, the file name is libTest. so.
I. Environment preparation
Copy the generated libTest. so file to the/usr/lib directory, run the/sbin/ldconfig command to prepare the PHP source code file, and decompress it.
2. Develop a PHP Module
First, go to the ext directory in the PHP source code directory and execute the following command :#. /ext_skel -- extname = after the custom Module name is executed, a folder named "Custom Module name" is generated. Enter this folder and edit config. the following code is found in the m4 file: dnl PHP_ARG_WITH (Test, for Test support,
Dnl Make sure that the comment is aligned:
Dnl [-- with-Test Include Test support]) or dnl PHP_ARG_ENABLE (Test, whether to enable Test support,
Dnl Make sure that the comment is aligned:
Dnl [-- enable-Test Enable Test support]) removes the dnl before each line. If you want to use dynamic reference, we recommend using -- enable-Test.
3. Compile the call Function
Edit the Test. c file and find the following code: zend_function_entry Test_functions [] = {
PHP_FE (confirm_Test_compiled, NULL)/* For testing, remove later .*/
PHP_FE (test, NULL)/* adds this line. test indicates the name of the function call in the PHP file */
{NULL, NULL, NULL}/* Must be the last line in Test_functions [] */
}; Add the code PHP_FUNCTION (Test) at the end of the test. c file)
{
RETURN_STRING (testPhpModule ());
} Compile: $./configure-with-php-config =$ {PHP_HOME}/bin/php-config
$ Make LDFLAGS =-lTest
$ Make test
Iv. Test Module
Copy the so file of the compiled module to the Apache directory: # cp modules/Test. so/usr/local/apache2/htdocs/edit the PHP file # vi test in the/usr/local/apache2/htdocs/directory. the code in the PHP file is as follows: <? Php
Dl ("Test. so ");
Echo test ();
?> Start Apache and access test. php. If it succeeds, the page displays the same output result as the main () function.
This article from the "Xuan Wu Ba Yi" blog, please be sure to keep this source http://commandos.blog.51cto.com/154976/130700