Welcome to the Flake documentation. This guide will help you get started with building high-performance PHP servers using the Flake framework.
Flake is a PHP server/daemon framework that supports both forking and event-driven patterns. It provides a simple yet powerful API for building network servers.
git clone https://github.com/animeshkundu/flake.git
Here's a simple example of creating a TCP server:
<?php
require_once 'flake.php';
class MyHandler extends \Flake\Handler {
public function Handle_Read($data) {
$this->Write("Hello from Flake!\n");
}
}
$core = new \Flake\Core();
$core->Listen('tcp://0.0.0.0:8080', 'MyHandler');
$core->Run();
The base class for all socket operations. Handles read/write operations, TLS/SSL support, and buffer management.
Listens for incoming connections on a specified address and port. Creates new Handler instances for each connection.
Base class for protocol handlers. Extend this class to implement your own protocol logic.
The main event loop. Manages all listeners and handlers, and dispatches events.
Each connection is handled by a separate forked process. This provides isolation and safety - if one handler crashes, others are unaffected.
Uses libevent for high-performance I/O multiplexing. All connections are handled in a single process.