Here is the script that I have ... I have a library from a provider that does encryption / decryption as part of the product used (I donβt know how it works under the hood). I built a PHP extension and everything works brilliantly through the CLI. Here is the raptor.c file that I wrote for the PHP extension:
#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, NULL, NULL, NULL, NULL, 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, "s", &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
and applicable fragments of the raptor.h file of the provider:
unsigned char *decNK(unsigned char * s, size_t inLen, size_t * outLen); unsigned char *encNK(unsigned char * s, size_t inLen, size_t * outLen);
My test.php file has really simple code:
<?php $x = 1; echo "$x\n"; $y = raptor_encNK($x); echo "$y\n"; $x = raptor_decNK($y); echo "$x\n"; ?>
From the CLI I get (the output of $ y changes with each run, but the final output is always correct)
# /usr/local/bin/php -f /usr/local/var/htdocs/test.php 1 FL//haHZgltG 1
The same code is received through the browser (again displays $ y changes, the final output is always crap)
1 TgPw72NF9Zby <binary crap>
So, I think that something is lost in translation when it goes to Apache ... or I screwed the extension and I can not understand it ... or, perhaps, both of them. I just don't understand why this works through the CLI and not through Apache.