-
Notifications
You must be signed in to change notification settings - Fork 4
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']]; | ||
|
||
// (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. | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.