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.4(1w ago)14942.4k↓43.2%9[1 PRs](https://github.com/ankane/onnxruntime-php/pulls)5MITPHPPHP &gt;= 8.2CI failing

Since Aug 25Pushed 1w ago7 watchersCompare

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

READMEChangelogDependencies (4)Versions (26)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

59

—

FairBetter than 98% of packages

Maintenance98

Actively maintained with recent releases

Popularity46

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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 ~60 days

Recently: every ~29 days

Total

24

Last Release

10d 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 (123 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

[zschuessler/laravel-route-to-class

A Laravel view composer that will convert the current route to a body class. 'admin/product/5/edit' becomes 'admin-product-edit'

26430.1k1](/packages/zschuessler-laravel-route-to-class)[serafim/properties

PHP properties implementation

779.1k1](/packages/serafim-properties)[codefog/contao-mobile_menu

mobile\_menu extension for Contao Open Source CMS

2140.4k](/packages/codefog-contao-mobile-menu)

PHPackages © 2026

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