PHPackages                             ankane/onnxruntime - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ankane/onnxruntime

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ankane/onnxruntime
==================

Run ONNX models in PHP

v0.3.1(2mo ago)14031.3k—8.6%8[1 PRs](https://github.com/ankane/onnxruntime-php/pulls)5MITPHPPHP &gt;= 8.2CI passing

Since Aug 25Pushed 2mo ago6 watchersCompare

[ Source](https://github.com/ankane/onnxruntime-php)[ Packagist](https://packagist.org/packages/ankane/onnxruntime)[ RSS](/packages/ankane-onnxruntime/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (23)Used By (5)

ONNX Runtime PHP
================

[](#onnx-runtime-php)

🔥 [ONNX Runtime](https://github.com/Microsoft/onnxruntime) - the high performance scoring engine for ML models - for PHP

Check out [an example](https://ankane.org/tensorflow-php)

[![Build Status](https://github.com/ankane/onnxruntime-php/actions/workflows/build.yml/badge.svg)](https://github.com/ankane/onnxruntime-php/actions)

Installation
------------

[](#installation)

Run:

```
composer require ankane/onnxruntime
```

Add scripts to `composer.json` to download the shared library:

```
    "scripts": {
        "post-install-cmd": "OnnxRuntime\\Vendor::check",
        "post-update-cmd": "OnnxRuntime\\Vendor::check"
    }
```

And run:

```
composer install
```

Note: On Mac x86-64, run `brew install onnxruntime` to download the shared library instead

Getting Started
---------------

[](#getting-started)

Load a model and make predictions

```
$model = new OnnxRuntime\Model('model.onnx');
$model->predict(['x' => [1, 2, 3]]);
```

> Download pre-trained models from the [ONNX Model Zoo](https://github.com/onnx/models)

Get inputs

```
$model->inputs();
```

Get outputs

```
$model->outputs();
```

Get metadata

```
$model->metadata();
```

Load a model from a stream

```
$stream = fopen('model.onnx', 'rb');
$model = new OnnxRuntime\Model($stream);
```

Get specific outputs

```
$model->predict(['x' => [1, 2, 3]], outputNames: ['label']);
```

Session Options
---------------

[](#session-options)

```
use OnnxRuntime\ExecutionMode;
use OnnxRuntime\GraphOptimizationLevel;

new OnnxRuntime\Model(
    $path,
    enableCpuMemArena: true,
    enableMemPattern: true,
    enableProfiling: false,
    executionMode: ExecutionMode::Sequential, // or Parallel
    freeDimensionOverridesByDenotation: null,
    freeDimensionOverridesByName: null,
    graphOptimizationLevel: GraphOptimizationLevel::None, // or Basic, Extended, All
    interOpNumThreads: null,
    intraOpNumThreads: null,
    logSeverityLevel: 2,
    logVerbosityLevel: 0,
    logid: 'tag',
    optimizedModelFilepath: null,
    profileFilePrefix: 'onnxruntime_profile_',
    sessionConfigEntries: null
);
```

Run Options
-----------

[](#run-options)

```
$model->predict(
    $inputFeed,
    outputNames: null,
    logSeverityLevel: 2,
    logVerbosityLevel: 0,
    logid: 'tag',
    terminate: false
);
```

Inference Session API
---------------------

[](#inference-session-api)

You can also use the Inference Session API, which follows the [Python API](https://onnxruntime.ai/docs/api/python/api_summary.html).

```
$session = new OnnxRuntime\InferenceSession('model.onnx');
$session->run(null, ['x' => [1, 2, 3]]);
```

The Python example models are included as well.

```
OnnxRuntime\Datasets::example('sigmoid.onnx');
```

GPU Support
-----------

[](#gpu-support)

### Linux and Windows

[](#linux-and-windows)

Download the appropriate [GPU release](https://github.com/microsoft/onnxruntime/releases) and set:

```
OnnxRuntime\FFI::$lib = 'path/to/lib/libonnxruntime.so'; // onnxruntime.dll for Windows
```

and use:

```
$model = new OnnxRuntime\Model('model.onnx', providers: ['CUDAExecutionProvider']);
```

### Mac

[](#mac)

Use:

```
$model = new OnnxRuntime\Model('model.onnx', providers: ['CoreMLExecutionProvider']);
```

History
-------

[](#history)

View the [changelog](https://github.com/ankane/onnxruntime-php/blob/master/CHANGELOG.md)

Contributing
------------

[](#contributing)

Everyone is encouraged to help improve this project. Here are a few ways you can help:

- [Report bugs](https://github.com/ankane/onnxruntime-php/issues)
- Fix bugs and [submit pull requests](https://github.com/ankane/onnxruntime-php/pulls)
- Write, clarify, or fix documentation
- Suggest or add new features

To get started with development:

```
git clone https://github.com/ankane/onnxruntime-php.git
cd onnxruntime-php
composer install
composer test
```

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance86

Actively maintained with recent releases

Popularity45

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~64 days

Recently: every ~74 days

Total

21

Last Release

74d ago

PHP version history (3 changes)v0.1.0PHP &gt;= 8.0

v0.2.0PHP &gt;= 8.1

v0.3.0PHP &gt;= 8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/220358?v=4)[Andrew Kane](/maintainers/ankane)[@ankane](https://github.com/ankane)

---

Top Contributors

[![ankane](https://avatars.githubusercontent.com/u/220358?v=4)](https://github.com/ankane "ankane (115 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ankane-onnxruntime/health.svg)

```
[![Health](https://phpackages.com/badges/ankane-onnxruntime/health.svg)](https://phpackages.com/packages/ankane-onnxruntime)
```

###  Alternatives

[zzstudio/think-addons

The ThinkPHP6 Addons Package

1518.6k](/packages/zzstudio-think-addons)[medialounge/magento2-storyblok-integration

Magento 2 extension to integrate Storyblok visual editor

2965.1k](/packages/medialounge-magento2-storyblok-integration)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
