Skip to content

Commit ca4e002

Browse files
committed
bump
1 parent c2be37a commit ca4e002

File tree

2 files changed

+34
-49
lines changed

2 files changed

+34
-49
lines changed

Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ ARG ASSERTIONS=0
5252
ARG OPTIMIZE=-O2
5353
# ARG PRE_JS=
5454
ARG INITIAL_MEMORY=256mb
55-
COPY ./source /src/source
5655
COPY --from=libxml /src/libxml2/build/ /src/usr
5756
COPY --from=sqlite /src/sqlite/sqlite3.o /src/usr/lib/
5857
COPY --from=sqlite /src/sqlite/sqlite3.h /src/usr/include/sqlite3/
@@ -93,6 +92,7 @@ RUN ./buildconf --force \
9392
RUN emmake make -j8
9493
# PHP7 outputs a libphp7 whereas php8 a libphp
9594
RUN bash -c '[[ -f .libs/libphp7.la ]] && mv .libs/libphp7.la .libs/libphp.la && mv .libs/libphp7.a .libs/libphp.a && mv .libs/libphp7.lai .libs/libphp.lai || exit 0'
95+
COPY ./source /src/source
9696
RUN emcc $OPTIMIZE \
9797
-I . \
9898
-I Zend \
@@ -105,7 +105,7 @@ RUN emcc $OPTIMIZE \
105105
RUN mkdir /build && emcc $OPTIMIZE \
106106
-o /build/php-$WASM_ENVIRONMENT.mjs \
107107
--llvm-lto 2 \
108-
-s EXPORTED_FUNCTIONS='["_pib_init", "_pib_destroy", "_pib_run", "_pib_exec", "_pib_refresh", "_php_embed_init", "_php_embed_shutdown", "_php_embed_shutdown", "_zend_eval_string"]' \
108+
-s EXPORTED_FUNCTIONS='["_phpw", "_phpw_flush", "_phpw_exec", "_phpw_run", "_php_embed_init", "_php_embed_shutdown", "_zend_eval_string"]' \
109109
-s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "UTF8ToString", "lengthBytesUTF8", "FS"]' \
110110
-s ENVIRONMENT=$WASM_ENVIRONMENT \
111111
-s FORCE_FILESYSTEM=1 \
@@ -116,7 +116,6 @@ RUN mkdir /build && emcc $OPTIMIZE \
116116
-s ERROR_ON_UNDEFINED_SYMBOLS=0 \
117117
-s MODULARIZE=1 \
118118
-s INVOKE_RUN=0 \
119-
# --pre-js=$PRE_JS \
120119
-s LZ4=1 \
121120
-s EXPORT_ES6=1 \
122121
-s EXPORT_NAME=createPhpModule \

source/pib_eval.c

Lines changed: 32 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,7 @@
88

99
int main() { return 0; }
1010

11-
int EMSCRIPTEN_KEEPALIVE pib_init()
12-
{
13-
putenv("USE_ZEND_ALLOC=0");
14-
15-
return php_embed_init(0, NULL);
16-
}
17-
18-
void pib_finally()
11+
void phpw_flush()
1912
{
2013
fflush(stdout);
2114
fprintf(stdout, "\n");
@@ -24,8 +17,9 @@ void pib_finally()
2417
fprintf(stderr, "\n");
2518
}
2619

27-
char *EMSCRIPTEN_KEEPALIVE pib_exec(char *code)
20+
char *EMSCRIPTEN_KEEPALIVE phpw_exec(char *code)
2821
{
22+
php_embed_init(0, NULL);
2923
char *retVal = NULL;
3024

3125
zend_try
@@ -37,59 +31,51 @@ char *EMSCRIPTEN_KEEPALIVE pib_exec(char *code)
3731
convert_to_string(&retZv);
3832

3933
retVal = Z_STRVAL(retZv);
40-
}
41-
zend_catch
42-
{
43-
}
34+
} zend_catch {
35+
} zend_end_try();
4436

45-
zend_end_try();
46-
47-
pib_finally();
37+
phpw_flush();
38+
php_embed_shutdown();
4839

4940
return retVal;
5041
}
5142

52-
int EMSCRIPTEN_KEEPALIVE pib_run(char *code)
43+
void EMSCRIPTEN_KEEPALIVE phpw_run(char *code)
5344
{
54-
int retVal = 255; // Unknown error.
55-
45+
php_embed_init(0, NULL);
5646
zend_try
5747
{
58-
retVal = zend_eval_string(code, NULL, "php-wasm run script");
59-
48+
zend_eval_string(code, NULL, "php-wasm run script");
6049
if(EG(exception))
6150
{
6251
zend_exception_error(EG(exception), E_ERROR);
63-
retVal = 2;
6452
}
65-
}
66-
zend_catch
67-
{
68-
retVal = 1; // Code died.
69-
}
70-
71-
zend_end_try();
72-
73-
pib_finally();
74-
75-
return retVal;
53+
// retVal = 2;
54+
// }
55+
} zend_catch {
56+
/* int exit_status = EG(exit_status); */
57+
} zend_end_try();
58+
59+
phpw_flush();
60+
php_embed_shutdown();
7661
}
7762

78-
char *pib_tokenize(char *code)
63+
void phpw(char *file)
7964
{
80-
// tokenize_parse(zval zend_string)
65+
php_embed_init(0, NULL);
8166

82-
return "";
83-
}
67+
zend_first_try {
68+
zend_file_handle file_handle;
69+
zend_stream_init_filename(&file_handle, file);
8470

85-
void EMSCRIPTEN_KEEPALIVE pib_destroy()
86-
{
87-
return php_embed_shutdown();
88-
}
89-
90-
int EMSCRIPTEN_KEEPALIVE pib_refresh()
91-
{
92-
pib_destroy();
71+
if (php_execute_script(&file_handle) == FAILURE) {
72+
php_printf("Failed to execute PHP script.\n");
73+
}
74+
zend_destroy_file_handle(&file_handle);
75+
} zend_catch {
76+
/* int exit_status = EG(exit_status); */
77+
} zend_end_try();
9378

94-
return pib_init();
79+
phpw_flush();
80+
php_embed_shutdown();
9581
}

0 commit comments

Comments
 (0)