通过CLI扩展PHP但不通过apache
发布时间:2020-12-13 22:32:30 所属栏目:PHP教程 来源:网络整理
导读:这是我的场景……我有来自供应商的库,它作为我们使用的产品的一部分进行加密/解密(不知道它是如何工作的).我构建了一个 PHP扩展,一切都通过CLI工作得非常好.这是我为PHP扩展编写的raptor.c文件: #ifdef HAVE_CONFIG_H#include "config.h"#endif#include "ph
这是我的场景……我有来自供应商的库,它作为我们使用的产品的一部分进行加密/解密(不知道它是如何工作的).我构建了一个
PHP扩展,一切都通过CLI工作得非常好.这是我为PHP扩展编写的raptor.c文件:
#ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" //#if HAVE_LIBRAPTOR #include "php_raptor.h" #include "raptor.h" #include "ext/standard/info.h" /* If you declare any globals in php_raptor.h uncomment this: ZEND_DECLARE_MODULE_GLOBALS(raptor) */ /* True global resources - no need for thread safety here */ static int le_raptor; /* {{{ raptor_functions[] * * Every user visible function must have an entry in raptor_functions[]. */ const zend_function_entry raptor_functions[] = { PHP_FE(raptor_decNK,NULL) PHP_FE(raptor_encNK,NULL) {NULL,NULL,NULL} /* Must be the last line in raptor_functions[] */ }; /* }}} */ /* {{{ raptor_module_entry */ zend_module_entry raptor_module_entry = { #if ZEND_MODULE_API_NO >= 20010901 STANDARD_MODULE_HEADER,#endif "raptor",raptor_functions,PHP_MINFO(raptor),#if ZEND_MODULE_API_NO >= 20010901 "0.1",/* Replace with version number for your extension */ #endif STANDARD_MODULE_PROPERTIES }; /* }}} */ #ifdef COMPILE_DL_RAPTOR ZEND_GET_MODULE(raptor) #endif /* {{{ PHP_MINFO_FUNCTION */ PHP_MINFO_FUNCTION(raptor) { php_info_print_table_start(); php_info_print_table_header(2,"raptor API support","enabled"); php_info_print_table_end(); } /* }}} */ PHP_FUNCTION(raptor_decNK) { char * enctext; unsigned char * dectext; int enctextsize; size_t dectextsize; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,"s",&enctext,&enctextsize) == FAILURE) { RETURN_NULL(); } dectext = decNK((unsigned char *) enctext,(size_t) enctextsize,&dectextsize); if (dectext == NULL) { RETURN_FALSE; } else { RETURN_STRINGL((char *) dectext,dectextsize,1); } } PHP_FUNCTION(raptor_encNK) { char * dectext; unsigned char * enctext; int dectextsize; size_t enctextsize; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,&dectext,&dectextsize) == FAILURE) { RETURN_NULL(); } enctext = encNK((unsigned char *) dectext,(size_t) dectextsize,&enctextsize); if (enctext == NULL) { RETURN_FALSE; } else { RETURN_STRINGL((char *) enctext,enctextsize,1); } } //#endif 和供应商的raptor.h文件的适用部分: unsigned char *decNK(unsigned char * s,size_t inLen,size_t * outLen); unsigned char *encNK(unsigned char * s,size_t * outLen); 我的test.php文件有非常简单的代码: <?php $x = 1; echo "$xn"; $y = raptor_encNK($x); echo "$yn"; $x = raptor_decNK($y); echo "$xn"; ?> 从我获得的CLI(每次运行输出$y更改,但最终输出始终正确) # /usr/local/bin/php -f /usr/local/var/htdocs/test.php 1 FL//haHZgltG 1 通过浏览器获得相同的代码(再次输出$y更改,最终输出始终为废话) 1 TgPw72NF9Zby <binary crap> 所以我认为,当它转到Apache时,有些东西会在翻译中丢失……或者我已经搞砸了扩展而无法解决它……或者两者兼而有之.我只是不明白为什么它可以通过CLI而不是通过Apache工作. 解决方法
所以最后它不是size_t的问题,而是代码中整数的大小.在使用CLI调用而不是使用Apache和Web浏览器时,为什么它可以正常工作仍然存在大量混淆……我可能永远都不知道.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |