aboutsummaryrefslogtreecommitdiffhomepage
path: root/services/sandbox-exec/wasm/php-wasm.c
blob: cef661f42da5282759c49f9f93ba88ac68ceec87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
#include <emscripten.h>
#include <Zend/zend_execute.h>
#include <sapi/embed/php_embed.h>

int EMSCRIPTEN_KEEPALIVE php_wasm_run(const char* code) {
    zend_result result;

    int argc = 1;
    char* argv[] = { "php.wasm", NULL };

    PHP_EMBED_START_BLOCK(argc, argv);

    result = zend_eval_string_ex(code, NULL, "php.wasm code", 1);

    PHP_EMBED_END_BLOCK();

    fprintf(stdout, "\n");
    fflush(stdout);
    fprintf(stderr, "\n");
    fflush(stderr);

    return result == SUCCESS ? 0 : 1;
}