PHP bridge to llama.cpp for local and remote LLM inference — no Python service required.

Maintainers

Package info

github.com/Cybergeon-Technologies/llama-bridge

pkg:composer/cybergeon-technologies/llama-bridge

Transparency log

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2026-07-29 02:46 UTC

This package is auto-updated.

Last update: 2026-07-29 05:07:50 UTC


README

Bring local & remote LLM inference to any PHP app — no Python service required.

Llama Bridge is a lightweight Composer package that lets PHP applications talk to llama.cpp — whether you're running it locally via FFI or connecting to a remote llama-server instance. Works on shared hosting, VPS, or dedicated infrastructure.

Why

Most PHP shops (WordPress, Laravel, Symfony) want to add AI features but end up standing up a separate Python microservice just to run inference. Llama Bridge removes that tax: point it at a llama-server endpoint (yours or a hosted one) and start generating text with a few lines of idiomatic PHP.

Requirements

  • PHP >= 8.1
  • Guzzle 7+ (installed automatically via Composer)
  • A running llama-server instance (see Setting up llama-server below)

Installation

composer require cybergeon-technologies/llama-bridge

Quickstart

use LlamaBridge\LlamaBridge;

$llm = new LlamaBridge([
    'remote' => ['endpoint' => 'http://your-llama-server:8080'],
]);

echo $llm->chat([
    ['role' => 'system', 'content' => 'You are a concise assistant.'],
    ['role' => 'user', 'content' => 'What is dependency injection in one sentence?'],
]);

That's it — no FFI setup, no shell access required. This works on any PHP host with outbound HTTP access, including standard shared hosting.

Usage

Simple completion

$response = $llm->complete("Explain recursion in one sentence.");
echo $response;

Chat (recommended)

$response = $llm->chat([
    ['role' => 'system', 'content' => 'You are a helpful coding assistant.'],
    ['role' => 'user', 'content' => 'Write a PHP function to reverse a string.'],
]);

echo $response;

Streaming

Stream tokens as they're generated — useful for chat UIs where you want output to feel instant:

$llm->chatStream(
    messages: [
        ['role' => 'user', 'content' => 'Write a haiku about the ocean.'],
    ],
    onToken: function (string $token) {
        echo $token;
        flush();
    }
);

If streaming to a browser, disable output buffering first: ob_end_flush(); before the loop, or configure your web server (e.g. disable gzip buffering in Nginx) to allow chunked output.

Options

$llm->chat($messages, [
    'max_tokens'  => 512,
    'temperature' => 0.3,
]);

Setting up llama-server

Llama Bridge is a client — you need a running llama-server to talk to. Quick setup on a VPS:

# Install build tools
sudo apt update && sudo apt install -y build-essential cmake git

# Build llama.cpp
git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
cmake -B build -DGGML_NATIVE=ON
cmake --build build --config Release -j$(nproc)

# Download a small quantized model
mkdir -p models && cd models
curl -L -o model.gguf "https://huggingface.co/<model-repo>/resolve/main/<model-file>.gguf"
cd ..

# Run the server
./build/bin/llama-server \
  -m models/model.gguf \
  --host 0.0.0.0 \
  --port 8080 \
  -c 4096 \
  --api-key "your-secret-key"

For production, run it as a systemd service so it survives reboots and crashes — see docs/llama-server-setup.md for the full unit file and hardening notes.

Authentication

If your llama-server is protected with --api-key, pass it through:

$llm = new LlamaBridge([
    'remote' => [
        'endpoint' => 'http://your-llama-server:8080',
        'api_key'  => 'your-secret-key',
    ],
]);

Roadmap

  • HTTP client — completion & chat, blocking and streaming
  • FFI local inference mode (run llama.cpp in-process on VPS/dedicated hosts with FFI enabled)
  • Auto-detect mode — automatically use FFI when available, fall back to HTTP otherwise
  • Retry/backoff and timeout handling for streaming connections
  • Laravel service provider + facade

Contributing

Issues and PRs welcome. This project is early — feedback on the API shape is especially valuable right now.

License

MIT