I have previously written a PHP extension DLL, which is an extension implemented by calling the system's comport and cannot be truly integrated with PHP. After studying the source code of PHP, I found some information on the Internet and tried to write an extension DLL. the test is okay. The following describes the specific extension method:... SyntaxHighlighter. all ();
I have previously written a PHP extension DLL, which is an extension implemented by calling the system's comport and cannot be truly integrated with PHP. After studying the source code of PHP, I found some information on the Internet and tried to write an extension DLL. the test is okay. The following describes the specific extension methods:
1, first Download php source code from www.php.net website, here take the php-5.2.17 version as an example, download and decompress to E: under the root directory (directory can be customized by yourself ).
2. download and install VC ++ 6.0. because the PHP source code is written in version 6.0, it is not surprising to use this version for Compilation. Other versions are not tested.
3. add the absolute path Microsoft Visual Studio \ Common \ MSDev98 \ Bin in the installation directory of VC ++ 6.0 to the system environment variable.
4. go to the E: \ php-5.2.17 \ ext Directory, copy the skeleton folder, and rename it the name of the extension to be developed, in this example "myfun ".
5. rename skeleton. c to myfun. c, and skeleton. dsp to myfun. dsp.
6. edit the php_skeleton.h, myfun. c, and myfun. dsp files in the myfun Directory. replace all extnames with myfun and extname with MYFUN. (Case sensitive)
The encoding phase is as follows:
7. open the php_skeleton.h File (header file) and find PHP_FUNCTION (confirm_myfun_compiled); in PHP_FUNCTION (functions);, write PHP_FUNCTION (mb_MessageBox) below; declare an mb_MessageBox function, this function is only used to output an alert message box in js for testing.
8. define the function entry below to open myfun. in the c file, find PHP_FE (confirm_myfun_compiled, NULL); and write PHP_FE (mb_MessageBox, NULL) below. Note that PHP_FE is a macro defined here, so no quotation marks are needed.
9. Compile the entity part of the function at the end of myfun. c:
PHP_FUNCTION (mb_MessageBox)
{
Char * arg = NULL;
Int arg_len, len;
Char * strg;
If (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC, "s", & arg, & arg_len) = FAILURE ){
Return;
}
Len = spprintf (& strg, 0, "script" alert ('% s') script ", arg); // This is the input js code.
RETURN_STRINGL (strg, len, 0 );
}
Now that the code is written, compile the code as follows:
10. Start-> Run. enter CMD to open the command line window.
11. go to the myfun Directory, enter msdev myfun. dsp/MAKE "myfun-Win32 Release_TS", and press enter to compile.
12. if there is no error, a Release_TS folder will be generated under E: \ php-5.2.17, in which you can find the php_myfun.dll file.
Now that the dll extension development is complete, we will test it in php:
13. copy php_myfun.dll to the ext folder in the original php directory.
14. open the php. ini file and add the extended extension = php_myfun.dll of the current dll.
15. restart IIS or apache, create a new file under the website directory, and enter the following content:
Echo mb_MessageBox ("test PHP extension DLL by horse ?? Quot ;);
?>
View to see the effect, as shown in the following figure:
Add extension:
Php code:
Final effect:
Extension information in phpinfo:
So far, php extension development has been completed
Author Ma ?? /P>