C:\phpsrc\ext>php ext_skel_win32.php
ext_skel --extname=module [--proto=file] [--stubs=file] [--xml[=file]]
[--skel=dir] [--full-xml] [--no-help]
--extname=module module is the name of your extension
--proto=file file contains prototypes of functions to create
--stubs=file generate only function stubs in file
--xml generate xml documentation to be added to phpdoc-cvs
--skel=dir path to the skeleton directory
--full-xml generate xml documentation for a self-contained extension
(not yet implemented)
--no-help don't try to be nice and create comments in the code
and helper functions to test if the module compiled
PHP Warning: fopen(/.php): failed to open stream: No such file or directory in
C:\phpsrc\ext\ext_skel_win32.php on line 52
C:\phpsrc\ext>
可以看到如何使用这php脚本。大体命令如下
c:\phpsrc\ext>php ext_skel_win32.php --extname=test
Creating directory test
Creating basic files: config.m4 config.w32 .svnignore test.c php_test.h CREDITS EXPERIMENTAL tests/001.phpt test.php [do
ne].
To use your new extension, you will have to execute the following steps:
1. $ cd ..
2. $ vi ext/test/config.m4
3. $ ./buildconf
4. $ ./configure --[with|enable]-test
5. $ make
6. $ ./php -f ext/test/test.php
7. $ vi ext/test/test.c
8. $ make
Repeat steps 3-6 until you are satisfied with ext/test/config.m4 and
step 6 confirms that your module is compiled into PHP. Then, start writing
code and repeat the last two steps as often as necessary.
c:\phpsrc\ext>
这样就成功创建了一个php扩展骨架
,你可以在里面修改。具体的还要好好研究PHP API。具体扩展的位置就在ext目录下,打开可以看到test文件夹,这就是刚才命令创建的。
PHP_FUNCTION(test){
php_printf("Hello C extension");
}
在数组zend_function_entry test_functions[]增加一行
const zend_function_entry test_functions[] = {
PHP_FE(confirm_test_compiled,NULL)/* For testing, remove later. */
PHP_FE(test, NULL) // 新增的行
PHP_FE_END/* Must be the last line in test_functions[] */
}; V. 构建DLL文件
用vc6打开我们的工程,就是test.dsp
1. 修改编译方式为release: 选择Build->Set Active Configuration设置默认编译方式为Release, 否则会提示缺少php5ts_debug.lib ,其实就是php5ts.lib。