---------外部c函数 hello.c----------
#include
#include
#include
#include
#include
int hello_cc(char * dbg)
{
syslog(log_debug, hello_cc %s\n, dbg);
if(dbg==null) return -1;
if(strlen(dbg)>1024) return -1;
printf(%s\n, dbg);
syslog(log_debug, hello_cc return\n);
return 0;
}
---------php5扩展函数 hello.c-----------
const zend_function_entry hello_functions[] = {
php_fe(confirm_hello_compiled, null) /* for testing, remove later. */
php_fe(hello, null)
php_fe_end /* must be the last line in hello_functions[] */
};
php_function(confirm_hello_compiled)
{
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, congratulations! you have successfully modified ext/%.78s/config.m4. module %.78s is now compiled into php., hello, arg$
return_stringl(strg, len, 0);
}
php_function(hello){
char *dbg = null;
int dbg_len, len;
int result;
if(zend_parse_parameters(zend_num_args() tsrmls_cc, s, &dbg, &dbg_len) == failure){
return;
}
res_cc = hello_cc(dbg);
return_long(res_cc);
}
------------php5 调用-------------
if (!extension_loaded(hello)) {
print skip;
} else {
//dl('hello.so'); //php5中dl()被屏蔽,直接在php.ini中添加hello.so
echo hello(ssssssssqqqqqqqqqqqq);
}
//输出-->> 空白页,估计崩掉了。
求解正确的 php_function(hello) ,急用!!!
------解决方案--------------------
如果 hello_cc 定义没有错误的话,放在一起编译就可以了
不过你在 hello_cc 中直接 printf 似违反了 php 扩展的约定了吧
