-
-
Save arnaud-lb/d0f2282e66def91a6ee34e1537b3ac5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _GNU_SOURCE | |
#include <sys/types.h> | |
#include <unistd.h> | |
#include <signal.h> | |
#include <string.h> | |
#include <pthread.h> | |
#include <sapi/embed/php_embed.h> | |
void *thread_routine(void *data) | |
{ | |
/* Invokes the Zend Engine initialization phase: SAPI (SINIT), modules | |
* (MINIT), and request (RINIT). It also opens a 'zend_try' block to catch | |
* a zend_bailout(). | |
*/ | |
PHP_EMBED_START_BLOCK(0, NULL) | |
php_printf( | |
"Number of functions loaded: %d\n", | |
zend_hash_num_elements(EG(function_table)) | |
); | |
/* Close the 'zend_try' block and invoke the shutdown phase: request | |
* (RSHUTDOWN), modules (MSHUTDOWN), and SAPI (SSHUTDOWN). | |
*/ | |
PHP_EMBED_END_BLOCK() | |
} | |
int main(int argc, char **argv) | |
{ | |
pthread_t thread; | |
pthread_create(&thread, NULL, thread_routine, NULL); | |
pthread_join(thread, NULL); | |
kill(getpid(), SIGINT); | |
sleep(1); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: | |
gcc \ | |
$$(php-config --includes) \ | |
-L$$(php-config --prefix)/lib \ | |
embed.c \ | |
-lphp \ | |
-Wl,-rpath=$$(php-config --prefix)/lib | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment