Qbix

Qbix Server

Your server is running. Now build something.

PHP 7.4.26 ยท PID 27861

Execution models

๐ŸŒ HTTP

Drop files in web/. Static files served from an in-memory cache, PHP scripts forked and executed. Add --workers=N for persistent workers with 100ร— more concurrent capacity.

fork ยท octane mode

๐Ÿ”Œ WebSocket

One process per connection. User isolation, auth, private state. Socket.IO compatible.

process per connection

๐Ÿ  Rooms

One process per room. Shared state for chat, games, collaboration. No Redis needed.

process per room

Project structure

your-project/
โ”œโ”€โ”€ qbixserver.php
โ”œโ”€โ”€ config/
โ”‚   โ””โ”€โ”€ server.json        โ† optional config
โ”œโ”€โ”€ web/                    โ† document root
โ”‚   โ”œโ”€โ”€ index.html          โ† replaces this page
โ”‚   โ””โ”€โ”€ api/hello.php       โ† HTTP endpoint
โ”œโ”€โ”€ handlers/               โ† WebSocket + room handlers
โ”‚   โ”œโ”€โ”€ chat/
โ”‚   โ”‚   โ”œโ”€โ”€ join.php        โ† per-connection
โ”‚   โ”‚   โ””โ”€โ”€ room/
โ”‚   โ”‚       โ”œโ”€โ”€ join.php    โ† room lifecycle
โ”‚   โ”‚       โ”œโ”€โ”€ message.php โ† room event
โ”‚   โ”‚       โ””โ”€โ”€ leave.php
โ”‚   โ””โ”€โ”€ connect.php         โ† on WebSocket connect
โ”œโ”€โ”€ classes/                โ† autoloaded
โ”‚   โ””โ”€โ”€ ChatRoom.php        โ† shared room state
โ””โ”€โ”€ errors/                 โ† custom error pages (optional)
    โ””โ”€โ”€ 404.php

Examples

1. HTTP endpoint

Any file in web/ is served. PHP files are executed in a forked process.

<?php
// web/api/hello.php โ€” visit /api/hello.php?name=Alice
Q_WebServer_State::header('Content-Type: application/json');
echo json_encode([
    'message' => 'Hello, ' . ($_GET['name'] ?? 'world')
]);

2. WebSocket handler

Each connection gets its own process. Configure in config/server.json:

{
  "Q": {
    "webserver": {
      "sockets": {
        "events": {
          "_connect": "connect",
          "chat/join": "chat/join"
        },
        "rooms": {
          "chat/$room": {"handler": "chat/room"}
        }
      }
    }
  }
}
<?php
// handlers/chat/join.php
function chat_join(&$params, &$result) {
    extract($params); // $socket, $event, $data
    $socket->join('chat/' . $data['room'], [
        'name' => $data['name']
    ]);
    $result = ['joined' => $data['room']];
}

3. Rooms โ€” shared state

All members share one process. State lives in class statics.

<?php
// handlers/chat/room/message.php
function chat_room_message(&$params, &$result) {
    extract($params); // $room, $event, $data
    $name = ChatRoom::$names[$room->socketId] ?? 'anon';
    $room->broadcast([
        'event' => 'chat/message',
        'data'  => ['name' => $name, 'text' => $data['text']]
    ]);
}

4. Browser client

<script src="/socket.io/socket.io.js"></script>
<script>
const socket = io({transports: ['websocket']});
socket.emit('chat/join', {room: 'general', name: 'Alice'});
socket.on('chat/message', (d) => console.log(d.name + ': ' + d.text));
socket.emit('chat/message', {text: 'Hello!'});
</script>
Next: Open the Control Panel to set your password, add users, and configure the server. Create web/index.html to replace this page. Read the Getting Started guide for the full walkthrough.
Qbix Server ยท web/index.html replaces this page