您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php5调用外部C库,解决思路

2024/4/25 4:33:01发布544次查看
php5调用外部c库,急!
---------外部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 扩展的约定了吧
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product