This is actually the scenario I've... I've library from the vendor that does file encryption/decryption included in an item we use (no clue how it operates underneath the hood). I built a PHP extension and everything works superbly through the CLI. This is actually the raptor.c file I authored for that 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 also the relevant bits of the vendor's raptor.h file:

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 truly simple code:

<?php
$x = 1;
echo "$x\n";
$y = raptor_encNK($x);
echo "$y\n";
$x = raptor_decNK($y);
echo "$x\n";
?>

In the CLI I recieve (output $y changes with every run, but final output always correct)

# /usr/local/bin/php -f /usr/local/var/htdocs/test.php
1
FL//haHZgltG
1

Exactly the same code with the browser will get (again output $y changes, final output always garbage)

1
TgPw72NF9Zby
<binary crap>

So I am thinking something gets lost in translation if this would go to Apache... or I've messed up the extension and should not decipher it... or possibly both. I simply do not understand why it might work through the CLI and never via Apache.

Exactly what does the apache error_log report? That's probably where you will find an idea towards the cause.

Personally, I'd suspect a permissions problem - keep in mind that the apache user has limited permissions - certainly more limited than yours in the command line.

So ultimately it had not been an problem with size_t but how big an integer inside their code. There's still very real problem why it really works when known as through the CLI versus using Apache along with a internet browser... I might never discover.