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

docs: Add README #5

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 53 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,57 @@
# Extism PHP Host SDK

PHP SDK for the extism WebAssembly Plugin-System.
# Using the PHP Host SDK

> *Note*: Please be sure you've [installed Extism](/docs/install) before continuing with this guide.

### 1. Install the PHP library

Install via [Packagist](https://packagist.org/):
```sh
composer require extism/extism
```

> *Note*: For the time being you may need to add a minimum-stability of "dev" to your composer.json
> ```json
> {
> "minimum-stability": "dev",
> }
> ```

### 2. Import the library and use the APIs

> *Note*: `code.wasm` in this example is our example plugin that counts vowels. If you want to run this, download it first and set the path:
> ```
> curl https://raw.githubusercontent.com/extism/extism/main/wasm/code.wasm > code.wasm
> ```

```php title=index.php
<?php

require_once __DIR__ . '/vendor/autoload.php';

// See the manifest docs for more options https://extism.org/docs/concepts/manifest
$wasm = (object) [ 'wasm' => [](object) [ 'path'] = './code.wasm']];
Copy link

@chrisdickinson chrisdickinson Nov 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on php v8.3.0 (installed via homebrew) this throws a syntax error.

Suggested change
$wasm = (object) [ 'wasm' => [](object) [ 'path'] = './code.wasm']];
$wasm = (object) [ 'wasm' => (object) ['path' => './code.wasm']];


// (or, simpler but less efficiently: $wasm = file_get_contents("./code.wasm");

// NOTE: if you encounter an error such as:
// "Unable to load plugin: unknown import: wasi_snapshot_preview1::fd_write has not been defined"
// pass `true` after $wasm in the following function to provide WASI imports to your plugin.
$plugin = new \Extism\Plugin($wasm);

$output = $plugin->call("count_vowels", "this is an example");
$json = json_decode(pack('C*', ...$output));
echo "Vowels counted = " . $json->{'count'} . PHP_EOL;
```

> *Note*: On some MacOS devices (particularly Apple Silicon), you may hit an error regarding the `Security.framework`. We're working on a solution here, but in the meantime, if this happens to you please file an issue or comment here: [https://github.com/extism/extism/issues/96](https://github.com/extism/extism/issues/96).

### Need help?

If you've encountered a bug or think something is missing, please open an issue on the [Extism GitHub](https://github.com/extism/extism) repository.

There is an active community on [Discord](https://discord.gg/cx3usBCWnc) where the project maintainers and users can help you. Come hang out!


> **Note**: This is an early 1.0 release and is unstable until we hit 1.0. If you are looking to integrate now consider looking at the 0.x version in the [extism/extism](https://github.com/extism/extism/tree/main/php) repo.

Loading