Skip to content

Commit

Permalink
Enable CURL in Playground Web (#1935)
Browse files Browse the repository at this point in the history
Enables the CURL PHP extension on
[playground.wordpress.net](http://playground.wordpress.net/) when
networking is enabled. This is made possible by the TLS 1.2
implementation merged in #1926.

This PR:

* Enables the curl extension
* Rebuilds PHP.wasm for the web
* Enables curl_exec and curl_multiexec functions in web browsers
* **Strips the response content-length and switches to
Transfer-Encoding: Chunked**
* Unrelated – adds a JSPI vs Asyncify indication to the SAPI name so
that we can easily learn which PHP.wasm build Playground is running

Related to #85
Closes #1008

## Why use Transfer-Encoding: chunked?

Web servers often respond with a combination of Content-Length
and Content-Encoding. For example, a 16kb text file may be compressed
to 4kb with gzip and served with a Content-Encoding of `gzip` and a
Content-Length of 4KB.

The web browser, however, exposes neither the Content-Encoding header
nor the gzipped data stream. All we have access to is the original
Content-Length value of the gzipped file and a decompressed data stream.

If we just pass that along to the PHP-side request handler, it would
see a 16KB body stream with a Content-Length of 4KB. It would then
truncate the body stream at 4KB and discard the rest of the data.

This is not what we want.

To correct that behavior, we're stripping the Content-Length entirely.
We do that for every single response because we don't have any way
of knowing whether any Content-Encoding was used. Furthermore, we can't
just calculate the correct Content-Length value without consuming the
entire content stream – and we want to pass each data chunk to PHP
as we receive it.

Instead of a fixed Content-Length, this PR uses Content-Encoding:
Chunked,
and then provides a per-chunk Content-Length. 

## Testing instrucions

Confirm the new E2E tests are sound and that they work in CI. You could
also try installing a CURL-reliant plugin such as Plausible and confirm
it installs without the fatal errors reported in #1008
  • Loading branch information
adamziel authored Oct 24, 2024
1 parent 616897c commit b25c7a4
Show file tree
Hide file tree
Showing 43 changed files with 296 additions and 67 deletions.
13 changes: 2 additions & 11 deletions packages/php-wasm/compile/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ const platformDefaults = {
WITH_LIBZIP: 'yes',
WITH_SQLITE: 'yes',
WITH_JSPI: 'no',
},
web: {
WITH_CURL: 'yes',
WITH_FILEINFO: 'yes',
WITH_ICONV: 'yes',
WITH_LIBXML: 'yes',
Expand All @@ -137,19 +136,11 @@ const platformDefaults = {
WITH_OPENSSL: 'yes',
WITH_WS_NETWORKING_PROXY: 'yes',
},
web: {},
node: {
WITH_CURL: 'yes',
WITH_FILEINFO: 'yes',
WITH_ICONV: 'yes',
WITH_LIBXML: 'yes',
WITH_GD: 'yes',
WITH_MBSTRING: 'yes',
WITH_MBREGEX: 'yes',
WITH_CLI_SAPI: 'yes',
WITH_OPENSSL: 'yes',
WITH_NODEFS: 'yes',
WITH_MYSQL: 'yes',
WITH_WS_NETWORKING_PROXY: 'yes',
},
};
const platform = args.PLATFORM;
Expand Down
6 changes: 5 additions & 1 deletion packages/php-wasm/compile/php/php_wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,11 @@ static char *wasm_sapi_getenv(char *name, unsigned long name_len)

SAPI_API sapi_module_struct php_wasm_sapi_module = {
"wasm", /* name */
"PHP WASM SAPI", /* pretty name */
#ifdef PLAYGROUND_JSPI
"PHP WASM SAPI (JSPI)", /* pretty name */
#else
"PHP WASM SAPI (Asyncify)", /* pretty name */
#endif

wasm_sapi_module_startup, /* startup */
wasm_sapi_shutdown_wrapper, /* shutdown */
Expand Down
3 changes: 1 addition & 2 deletions packages/php-wasm/universal/src/lib/php.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,7 @@ export class PHP implements Disposable {
'always_populate_raw_post_data = -1',
'upload_max_filesize = 2000M',
'post_max_size = 2000M',
'disable_functions = curl_exec,curl_multi_exec',
'allow_url_fopen = Off',
'allow_url_fopen = On',
'allow_url_include = Off',
'session.save_path = /home/web_user',
'implicit_flush = 1',
Expand Down
Binary file modified packages/php-wasm/web/public/php/asyncify/7_0_33/php_7_0.wasm
Binary file not shown.
Binary file modified packages/php-wasm/web/public/php/asyncify/7_1_30/php_7_1.wasm
Binary file not shown.
Binary file modified packages/php-wasm/web/public/php/asyncify/7_2_34/php_7_2.wasm
Binary file not shown.
Binary file modified packages/php-wasm/web/public/php/asyncify/7_3_33/php_7_3.wasm
Binary file not shown.
Binary file modified packages/php-wasm/web/public/php/asyncify/7_4_33/php_7_4.wasm
Binary file not shown.
Binary file modified packages/php-wasm/web/public/php/asyncify/8_0_30/php_8_0.wasm
Binary file not shown.
Binary file modified packages/php-wasm/web/public/php/asyncify/8_1_23/php_8_1.wasm
Binary file not shown.
Binary file modified packages/php-wasm/web/public/php/asyncify/8_2_10/php_8_2.wasm
Binary file not shown.
Binary file modified packages/php-wasm/web/public/php/asyncify/8_3_0/php_8_3.wasm
Binary file not shown.
6 changes: 3 additions & 3 deletions packages/php-wasm/web/public/php/asyncify/php_7_0.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/php-wasm/web/public/php/asyncify/php_7_1.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/php-wasm/web/public/php/asyncify/php_7_2.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/php-wasm/web/public/php/asyncify/php_7_3.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/php-wasm/web/public/php/asyncify/php_7_4.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/php-wasm/web/public/php/asyncify/php_8_0.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/php-wasm/web/public/php/asyncify/php_8_1.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/php-wasm/web/public/php/asyncify/php_8_2.js

Large diffs are not rendered by default.

Loading

0 comments on commit b25c7a4

Please sign in to comment.