PHPackages                             rubix/server - 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. [API Development](/categories/api)
4. /
5. rubix/server

ActiveLibrary[API Development](/categories/api)

rubix/server
============

Deploy your Rubix ML models to production with scalable stand-alone inference servers.

2.0.7(2mo ago)632.3k13MITPHPPHP &gt;=7.4CI failing

Since Nov 17Pushed 2mo ago6 watchersCompare

[ Source](https://github.com/RubixML/Server)[ Packagist](https://packagist.org/packages/rubix/server)[ Docs](https://github.com/RubixML/Server)[ GitHub Sponsors](https://github.com/sponsors/andrewdalpino)[ RSS](/packages/rubix-server/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (26)Versions (26)Used By (0)

Rubix Server
============

[](#rubix-server)

Rubix Server is a library for deploying your [Rubix ML](https://github.com/RubixML/ML) models to production. Our server wraps your trained estimator in an API that can be queried using standard protocols. Included is a real-time dashboard for monitoring the health and throughput of your models.

- **Optimized** for low latency predictions
- **Scale** by adding more instances
- **Monitoring** with real-time analytics dashboard
- **Robust** to common threats and failure modes

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

[](#installation)

Install Rubix Server using [Composer](https://getcomposer.org/):

```
$ composer require rubix/server
```

### Docker Image

[](#docker-image)

A [Docker Image](https://gitlab.com/torchello/rubix-ml-server-docker) is available for a quick start or deployment.

Requirements
------------

[](#requirements)

- [PHP](https://php.net/manual/en/install.php) 7.4 or above

Documentation
-------------

[](#documentation)

The latest documentation can be found in this README.

### Table of Contents

[](#table-of-contents)

- [Servers](#servers)
    - [HTTP Server](#http-server)
- [Server Middleware](#server-middleware)
    - [Access Log Generator](#access-log-generator)
    - [Basic Authenticator](#basic-authenticator)
    - [Shared Token Authenticator](#shared-token-authenticator)
    - [Trusted Clients](#trusted-clients)
- [Loggers](#loggers)
    - [File](#file)
- [FAQs](#faqs)

---

### Servers

[](#servers)

Rubix model servers are stand-alone processes that wrap an estimator in an API that can be queried over a network connection. Since servers implement their own networking stack, they can be run directly from the PHP command line interface (CLI) without the need for an intermediary server such as Nginx or Apache.

To boot up a server, pass a trained estimator instance to the `serve()` method:

```
public function serve(Estimator $estimator) : void
```

```
use Rubix\Server\HTTPServer;
use Rubix\ML\Classifiers\KNearestNeighbors;

$server = new HTTPServer('127.0.0.1', 8000);

$estimator = new KNearestNeighbors(5);

// Import a dataset

$estimator->train($dataset);

$server->serve($estimator);
```

Or, you can load a previously trained estimator from storage and serve it like in the example below.

```
use Rubix\ML\PersistentModel;
use Rubix\ML\Persisters\Filesystem;

$estimator = PersistentModel::load(new Filesystem('example.model'));

$server->serve($estimator);
```

> **Note**: The server will stay running until the process is terminated. It is a good practice to use a process monitor such as [Supervisor](http://supervisord.org/) to start and autorestart the server in case of a failure.

#### Shutting Down The Server

[](#shutting-down-the-server)

To gracefully shut down the server, send a quit signal (`SIGQUIT`) to the process. To shut down immediately, without waiting for current connections to close, you can either send a terminate (`SIGTERM`) or interrupt (`SIGINT`) signal.

> **Note:** Signal handling does not work in Windows environments.

For example, to shut down gracefully, first identify the server's process ID (PID) and then send the `QUIT` signal to it.

```
$ kill -s QUIT 1234
```

#### Verbose Interface

[](#verbose-interface)

Servers that implement the Verbose interface accept any PSR-3 compatible logger instance and begin logging critical information such as errors and start/stop events. To set a logger pass the PSR-3 logger instance to the `setLogger()` method on the server instance.

```
use Rubix\Server\Loggers\File;

$server->setLogger(new File('example.log'));
```

### HTTP Server

[](#http-server)

A JSON over HTTP server exposing Representational State Transfer (REST) and GraphQL APIs. The HTTP Server operates using ubiquitous standards making it compatible with a wide range of systems. In addition, it provides its own web-based user interface for real-time server monitoring.

Interfaces: [Server](#servers), [Verbose](#verbose-interface)

#### Parameters

[](#parameters)

\#ParamDefaultTypeDescription1host'127.0.0.1'stringThe host address to bind the server to. Use `'0.0.0.0'` to bind to all interfaces.2port8000intThe network port to run the HTTP services on.3certnullstringThe path to the certificate used to authenticate and encrypt the HTTP channel.4middlewares\[\]arrayThe stack of server middleware to run on each request/response.5max concurrent requests10intThe maximum number of requests that can be handled concurrently.6static assets cacheInMemoryCacheCacheThe cache used to serve static asset requests.7sse reconnect buffer50intThe maximum number of events to store in the server-sent events (SSE) reconnect buffer.#### PHP INI Configuration

[](#php-ini-configuration)

NameDefaultDescriptionmemory\_limit128MThe maximum amount of memory the server is allowed to consume.post\_max\_size8MThe maximum size of a request body the server can buffer.**Example**

```
use Rubix\Server\HTTPServer;
use Rubix\Server\HTTP\Middleware\\AccessLogGenerator;
use Rubix\Server\Loggers\File;
use Rubix\Server\HTTP\Middleware\\BasicAuthenticator;
use Rubix\Server\Services\Caches\InMemoryCache;

$server = new HTTPServer('127.0.0.1', 443, '/cert.pem', [
	new AccessLogGenerator(new File('access.log')),
	new BasicAuthenticator([
		'morgan' => 'secret',
		'taylor' => 'secret',
	]),
], 50, new InMemoryCache(86400), 100);
```

#### Routes

[](#routes)

The HTTP server exposes the following resources and their methods.

MethodURIDescriptionGET/uiThe web user interface.GET/ui/dashboardThe server dashboard interface.GET/modelReturn the properties of the model.POST/model/predictionsMake a set of predictions on a dataset.POST/model/probabilitiesReturn the joint probabilities of each sample in a dataset.POST/model/anomaly-scoresReturn the anomaly scores of each sample in a dataset.GET/serverReturn the properties of the server.GET/dashboard/eventsSubscribe to the dashboard events stream.POST/graphqlQuery the server using GraphQL.#### Server Analytics

[](#server-analytics)

The HTTP server provides its own high-level user interface (UI) to the GraphQL API it exposes under the hood offering features such as server monitoring and traffic visualization. To access the web interface, navigate to `http://hostname:port/ui` (or `https://hostname:port/ui` if using a secure socket connection) using your favorite modern web browser.

The example below is a screen capture of the server dashboard in dark mode.

[![Server Web UI Screenshot](https://raw.githubusercontent.com/RubixML/Server/master/docs/images/server-web-ui-screenshot.png)](https://raw.githubusercontent.com/RubixML/Server/master/docs/images/server-web-ui-screenshot.png)

#### References

[](#references)

> - R. Fielding et al. (2014). Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content.

---

### Server Middleware

[](#server-middleware)

HTTP middleware are processors of the incoming HTTP requests and outgoing responses produced by the request handler (or *Controller*). They allow the user to hook into the HTTP request/response cycle by inserting additional logic into the pipeline.

### Access Log Generator

[](#access-log-generator)

Generates an HTTP access log using a format similar to the Apache log format.

#### Parameters

[](#parameters-1)

\#ParamDefaultTypeDescription1loggerLoggerInterfaceA PSR-3 logger instance.**Example**

```
use Rubix\Server\HTTP\Middleware\\AccessLog;
use Rubix\Server\Loggers\File;

$middleware = new AccessLog(new File('access.log'));
```

```
[2020-11-04 23:10:57] INFO: 127.0.0.1 "POST /predictions HTTP/1.1" 200 140 - "Rubix ML REST Client/0.2.3"
[2020-11-04 23:11:54] INFO: 127.0.0.1 "POST /predictions/sample HTTP/1.1" 200 96 - "Rubix ML REST Client/0.2.3"
```

### Basic Authenticator

[](#basic-authenticator)

An implementation of HTTP Basic Auth as described in [RFC7617](https://tools.ietf.org/html/rfc7617).

> **Note:** This authorization strategy is only secure to man-in-the-middle attacks over HTTPS.

#### Parameters

[](#parameters-2)

\#ParamDefaultTypeDescription1passwordsarrayAn associative map from usernames to their passwords.2realm'auth'stringThe unique name given to the scope of permissions required for this server.**Example**

```
use Rubix\Server\HTTP\Middleware\\BasicAuthenticator;

$middleware = new BasicAuthenticator([
	'morgan' => 'secret',
	'taylor' => 'secret',
], 'ml models');
```

### Shared Token Authenticator

[](#shared-token-authenticator)

Authenticates incoming requests using a shared key that is kept secret between the client and server. It uses the `Authorization` header with the `Bearer` prefix to indicate the shared key.

> **Note:** This authorization strategy is only secure to man-in-the-middle attacks over HTTPS.

#### Parameters

[](#parameters-3)

\#ParamDefaultTypeDescription1tokensarrayThe shared secret keys (bearer tokens) used to authorize requests.2realm'auth'stringThe unique name given to the scope of permissions required for this server.**Example**

```
use Rubix\Server\HTTP\Middleware\\SharedTokenAuthenticator;

$middleware = new SharedTokenAuthenticator([
	'secret', 'another-secret',
], 'ml models');
```

### Trusted Clients

[](#trusted-clients)

A whitelist of clients that can access the server - all other connections will be dropped.

#### Parameters

[](#parameters-4)

\#ParamDefaultTypeDescription1ips\['127.0.0.1'\]arrayAn array of trusted client ip addresses.**Example**

```
use Rubix\Server\HTTP\Middleware\\TrustedClients;

$middleware = new TrustedClients([
	'127.0.0.1', '192.168.4.1', '45.63.67.15',
]);
```

Loggers
-------

[](#loggers)

PSR-3 compatible loggers for capturing important server events.

### File

[](#file)

A simple append-only file logger.

#### Parameters

[](#parameters-5)

\#NameDefaultTypeDescription1pathstringThe path to the append-only log file. A new file will be created if it doesn't exist yet.2channel''stringThe channel name that appears on each line.3timestampFormat'Y-m-d H:i:s'stringThe format of the timestamp.**Example**

```
use Rubix\Server\Loggers\File;

$logger = new File('server.log', 'example', 'Y-m-d H:i:s');
```

FAQs
----

[](#faqs)

Here you will find answers to the most frequently asked questions.

### How do I run the server?

[](#how-do-i-run-the-server)

All model servers are designed to be run from the PHP command line interface ([CLI](http://php.net/manual/en/features.commandline.php)). Model servers are long-running asynchronous processes that handle concurrent requests and implement their own networking stack avoiding the need for a third-party web server such as Nginx or Apache.

To run the server, you can execute your script containing the server code by entering the following on the command line.

```
$ php server.php
```

### Can I run the model server on the same host as a regular web server?

[](#can-i-run-the-model-server-on-the-same-host-as-a-regular-web-server)

Yes, model server are designed to coexist with other web servers (including other model servers) seamlessly. Just make sure that each server runs on its own unique port.

### How do I scale inference throughput?

[](#how-do-i-scale-inference-throughput)

Since model servers are inference-only (i.e. they only support queries), they scale horizontally by adding more instances behind a load balancer such as [Nginx](http://nginx.org).

### Do servers support compression?

[](#do-servers-support-compression)

Yes, the HTTP Server supports both Gzip and Deflate compression schemes applied to the request bodies and to the response bodies of requests for static assets.

License
-------

[](#license)

The code is licensed [MIT](LICENSE) and the documentation is licensed [CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/).

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance85

Actively maintained with recent releases

Popularity34

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 98.9% 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 ~95 days

Recently: every ~186 days

Total

25

Last Release

77d ago

Major Versions

0.4.0-beta → 1.0.0-rc12021-04-26

1.0.x-dev → 2.0.02023-09-19

PHP version history (3 changes)0.0.1-betaPHP &gt;=7.1.3

0.0.2-betaPHP &gt;=7.2

1.0.0-rc1PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/643b22cfe15a5f3ff42dc06ce98f1e5024b6e4578fc9627a058097f5046164d8?d=identicon)[andrewdalpino](/maintainers/andrewdalpino)

---

Top Contributors

[![andrewdalpino](https://avatars.githubusercontent.com/u/18690561?v=4)](https://github.com/andrewdalpino "andrewdalpino (281 commits)")[![torchello](https://avatars.githubusercontent.com/u/897885?v=4)](https://github.com/torchello "torchello (2 commits)")[![alexandreelise](https://avatars.githubusercontent.com/u/51425450?v=4)](https://github.com/alexandreelise "alexandreelise (1 commits)")

---

Tags

apihttp-serverinferenceinference-engineinference-serverinfrastructurejson-apimachine-learningmicroserviceml-infrastructuremodel-deploymentmodel-serverphpphp-machine-learningphp-mlrest-apirubix-mlrubix-serverphpapicloudgraphqlinferenceaiserverREST APIJSON-APImachine learningpredictionmldistributedgraph-qlRubixphp mlrubixmlrubix mlphp machine learningphp aiMicroservicerest-clientinfrastructurerest-serverinference engineinference serverml infrastructuremodel servermodel deploymentml server

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rubix-server/health.svg)

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

###  Alternatives

[rubix/ml

A high-level machine learning and deep learning library for the PHP language.

2.2k1.4M28](/packages/rubix-ml)[algolia/algoliasearch-client-php

API powering the features of Algolia.

69433.0M114](/packages/algolia-algoliasearch-client-php)[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.5k311.5k5](/packages/theodo-group-llphant)[deepseek-php/deepseek-php-client

deepseek PHP client is a robust and community-driven PHP client library for seamless integration with the Deepseek API, offering efficient access to advanced AI and data processing capabilities.

47073.9k5](/packages/deepseek-php-deepseek-php-client)[qwen-php/qwen-php-client

robust and community-driven PHP SDK library for seamless integration with the qwen AI API, offering efficient access to advanced AI and data processing capabilities

213.2k1](/packages/qwen-php-qwen-php-client)

PHPackages © 2026

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