Created
April 18, 2017 08:03
-
-
Save brzuchal/7ec7def2b4fb809773ca93cf4d7268a1 to your computer and use it in GitHub Desktop.
Embeding PHP7
This file contains hidden or 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
| #include <stdio.h> | |
| #include <unistd.h> | |
| #include <string.h> | |
| #include <sapi/embed/php_embed.h> | |
| #include <Zend/zend_stream.h> | |
| #include <Zend/zend.h> | |
| int main(int argc, char *argv[]) | |
| { | |
| zend_file_handle script; | |
| FILE *fp; | |
| if (argc != 2) { | |
| fprintf(stderr, "Usage: embed filename.php\n"); | |
| return -1; | |
| } | |
| if ((fp = fopen(argv[1], "rb")) == NULL) { | |
| fprintf(stderr, "Unable to open %s\n", argv[1]); | |
| return -1; | |
| } | |
| fclose(fp); | |
| argc--; | |
| argv++; | |
| PHP_EMBED_START_BLOCK(argc, argv) | |
| while (1) { | |
| // Do some 'work' | |
| script.type = ZEND_HANDLE_FP; | |
| script.filename = argv[0]; | |
| script.opened_path = NULL; | |
| script.free_filename = 0; | |
| if ((script.handle.fp = fopen(script.filename, "rb")) == NULL) { | |
| fprintf(stderr, "Unable to open %s\n", argv[1]); | |
| return -1; | |
| } | |
| php_execute_script(&script TSRMLS_CC); | |
| //zend_file_handle_dtor(&script); | |
| } | |
| PHP_EMBED_END_BLOCK() | |
| return 0; | |
| } |
This file contains hidden or 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
| CC=gcc | |
| CFLAGS=-c $(shell php-config --includes ) -Wall -g | |
| LDFLAGS=$(shell php-config --ldflags ) | |
| all: embed.c | |
| $(CC) -o embed.o embed.c $(CFLAGS) | |
| $(CC) -o embed embed.o $(LDFLAGS) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment