Skip to content

Instantly share code, notes, and snippets.

@anthonybishopric
Created October 19, 2012 00:50
Show Gist options
  • Save anthonybishopric/3915637 to your computer and use it in GitHub Desktop.
Save anthonybishopric/3915637 to your computer and use it in GitHub Desktop.
Inline C in PHP
<?php
// This is largely stolen from test.php in the Inline_C repo (https://github.com/pear/Inline_C/blob/master/test.php)
require_once("C.php");
$function1 = <<<EOF
PHP_FUNCTION(times)
{
long i,j;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &i,&j) == FAILURE) {
WRONG_PARAM_COUNT;
}
RETURN_LONG(i*j);
}
EOF;
$inline = new Inline_C();
$inline->add_code($function1);
$inline->compile();
echo "2 x 3 is " . times(2,3); // returns 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment