Skip to content

Instantly share code, notes, and snippets.

@arnaud-lb
Created October 1, 2022 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save arnaud-lb/d0f2282e66def91a6ee34e1537b3ac5f to your computer and use it in GitHub Desktop.
Save arnaud-lb/d0f2282e66def91a6ee34e1537b3ac5f to your computer and use it in GitHub Desktop.
#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;
}
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