-
Notifications
You must be signed in to change notification settings - Fork 43
libSSE docs
This is the documentation of libSSE. It explains how to use libSSE and shows all classes available.
class SSE {
public $exec_limit = 600;
public $sleep_time = 0.5;
public $client_reconnect;
public $allow_cors = false;
public $keep_alive_time = 300;
public $use_chunked_encoding = false;
public function __construct();
public function addEventListener($event_name,$handler);
public function removeEventListener($event_name);
public function start();
}
Default: 600 seconds
This is used to control the execution time of the script in order to save memory and CPU load. If you want to allow the script to run as long as possible, set this to 0.
Default: 0.5 seconds
The sleep time after each check for updates. Larger number means the data will be updated with more delay.
Default: false
Whether to allow cross domain access or not. If you're going to provide a real-time API to others or you're working with sub-domains you MUST set this to true.
Default: 300 seconds
The time interval of sending a comment signal to keep the connection alive. Recommend ranges are 5-15 minutes (300-900 seconds).
Default: false
Whether to use chunked encoding or not. Some server may send this header automatically and turning this on may get errors so make sure your server has no problem when turning this on.
Default: 1
The time for the client to reconnect after the connection has been broken.
Parameters
- $event_name - The event name
- $handler - The handler of the event, must be an instance of SSEEvent
Adds a event handler of the event named $event_name. When data is available from the handler libSSE will send them automatically.
Parameters
- $event_name - The event to remove
Removes the event handler specified by $event_name.
Start the whole event loop and sending of data.
class SSEEvent {
public function check();
public function update();
}
This is the base class for all events. All events should inherit this base class.
This is the method that will be called by libSSE regularly to check for updates for the specified event.
This is the method that will be called by libSSE to get the event data when an update happens.
class SSEData {
public function __construct($method,$credinals);
public function get($key);
public function set($key,$value);
public function delete($key);
public static function register($name,$class);
}
This class provides a simple key-value storage to allow cross-script communication.
Parameters
- $method - The method of storage, avaliable options are
mysql
,mysqli
,file
andapc
- $credinals - Extra information needed by a specific method of storage. Default: null
Parameters
- $key - The key to the corresponding value
Get the corresponding value by a key specified.
Parameters
- $key - The key of the corresponding value
- $value - The value
Set a value with a key and value.
Parameters
- $key - The key to the corresponding value
Deletes a value with a corresponding key.
The documentation is not completed yet. You can help me finish it if you want.