Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP: Support $env and $cwd proc_open arguments #1064

Merged
merged 6 commits into from
Feb 28, 2024

Conversation

adamziel
Copy link
Collaborator

@adamziel adamziel commented Feb 27, 2024

Description

Adds support for the following proc_open arguments: $env_vars and $cwd.

proc_open signature is:

function proc_open(
    $command,
    $descriptor_spec,
    &$pipes,
    $cwd = null,
    $env_vars = null,
    $options = null
): resource|false

With this PR, it may we called as follows:

proc_open(
    "php install-wordpress.php",
    [1 => [ 'pipe', 'w' ]],
    $pipes,
    '/wordpress',
    [ 'WP_VERSION' => '6.4' ]
)

And the spawn handler will be called as follows:

php.setSpawnHandler(
    createSpawnHandler(
        (command, processApi, options) => {
            console.log({ command, options });
            // {
            //     "command": "php install-wordpress.php",
            //     "options": { "cwd": "/wordpress", "env": { "WP_VERSION": "6.4" } }
            // }
        }
    )
)

Implementation

The proc_open C handler now passes the information from these arguments to the js_proc_open handler, which then propagates them to the spawn handler.

Testing instructions

Confirm the unit tests pass

@adamziel adamziel force-pushed the proc-open-support-env-cwd branch from 8737c76 to c08ae19 Compare February 27, 2024 09:50

Verified

This commit was signed with the committer’s verified signature. The key has expired.
addaleax Anna Henningsen

Verified

This commit was signed with the committer’s verified signature. The key has expired.
addaleax Anna Henningsen

Unverified

The email in this signature doesn’t match the committer email.
@adamziel adamziel force-pushed the proc-open-support-env-cwd branch from c08ae19 to e57fc09 Compare February 28, 2024 00:24
@adamziel adamziel merged commit 0eba044 into trunk Feb 28, 2024
5 checks passed
@adamziel adamziel deleted the proc-open-support-env-cwd branch February 28, 2024 12:30
adamziel added a commit that referenced this pull request Feb 28, 2024
## What is this PR doing?

Supersedes #1051

Adds a PHP Blueprints demo page where the use of
[blueprints.phar](WordPress/blueprints#28) PHP
library in Playground may be further explored. The showcase is
intentionally not added to
http://localhost:5400/website-server/demos/index.html as PHP Blueprints
may become a part of Playground core soon enough.

For more context see:

* #1025
* https://github.com/WordPress/blueprints

## How does it work?

* The built Blueprints library is included with this PR via the
`blueprints.phar` file
* A number of PHP.wasm improvements have been merged to support it:
   * #1064
   * #1065
   * #1069
* This PR ships a `fetch` subprocess handler to enable streaming network
data in the Blueprints library – it uses [a special network transport
called
`fetch`](https://github.com/WordPress/blueprints/blob/efa8deef56095bd5bcb94868787e29f7b54350f3/src/WordPress/DataSource/PlaygroundFetchSource.php)
that requests network data via `proc_open()` when running in Playground.
Why subprocesses? They provide everything a custom network handler
needs: pipes, asynchronous execution, exit codes, internal PHP plumbing.

## Follow-up work

* Support a real-time progress bar

## Testing instructions

Go to http://localhost:5400/website-server/demos/php-blueprints.html and
confirm it looks like on the screenshot below:

![CleanShot 2024-02-28 at 15 46
14@2x](https://github.com/WordPress/wordpress-playground/assets/205419/47a91d99-07f3-40a5-a046-b58f8cda952e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant