PHPackages                             madbyad/mpl-long-poll - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. madbyad/mpl-long-poll

ActiveLibrary[HTTP &amp; Networking](/categories/http)

madbyad/mpl-long-poll
=====================

A PHP Library to provide an easy way to implement real time communication with HTTP Long Polling

v1.0.0(2y ago)08MITPHPPHP &gt;= 7.0.0

Since May 9Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/MadByAd/MPL-LongPoll)[ Packagist](https://packagist.org/packages/madbyad/mpl-long-poll)[ RSS](/packages/madbyad-mpl-long-poll/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

[![Logo](./logo.png)](./logo.png)

MPL Long Poll
=============

[](#mpl-long-poll)

The MPL (MadByAd PHP Library) Long Poll is a library purposely created for providing an easy interface to implement a real time communication with HTTP Long Polling. Although HTTP Long Polling may be an outdated technique (because of WebSocket), it is easier to implement in PHP rather than Websocket, and can be used to create a seamless real time communication (though there may be slight delay in seconds)

- [MPL Long Poll](#mpl-long-poll)
    - [LongPoll Class](#longpoll-class)
        - [informPeer()](#informpeer)
        - [readAsPeer()](#readaspeer)
        - [setQueryTime()](#setquerytime)
        - [setJsonFlags()](#setjsonflags)
    - [Example](#example)
        - [Example 1](#example-1)
        - [Example 2](#example-2)

LongPoll Class
--------------

[](#longpoll-class)

The `LongPoll` class is used to provide an easy way to implement real time communication with HTTP Long Polling

### informPeer()

[](#informpeer)

The `LongPoll::informPeer(string $id, array $data)` method is used for sending a message (data) to the given peer. This method takes 2 parameter, the first is the peer id and the second is the data which should be in an associative array

### readAsPeer()

[](#readaspeer)

The `LongPoll::readAsPeer(string $id, bool $endExecution = true)` method is used for reading message (data) as the given peer. This method takes 1 parameter and 1 optional parameter, the parameter is the peer id and the optional parameter determine whether to end the execution after reading the message (data) by default it is set to `TRUE`

### setQueryTime()

[](#setquerytime)

The `LongPoll::setQueryTime(int $second)` method is use to set the query time (in seconds) the lower the query time the more responsive it is but more resource intensive it will be, the higher the query time the less responsive it is but less resource intensive it will be

### setJsonFlags()

[](#setjsonflags)

The `LongPoll::setJsonFlags(int $flags)` method is use to set the how the JSON message is formatted (only for debugging use). The list of avaible format is

- `JSON_HEX_QUOT`
- `JSON_HEX_TAG`
- `JSON_HEX_AMP`
- `JSON_HEX_APOS`
- `JSON_NUMERIC_CHECK`
- `JSON_PRETTY_PRINT`
- `JSON_UNESCAPED_SLASHES`
- `JSON_FORCE_OBJECT`
- `JSON_UNESCAPED_UNICODE`
- `JSON_THROW_ON_ERROR`

Example
-------

[](#example)

Here is two example of How Long Polling works

### Example 1

[](#example-1)

First we will create `read.php` and we will write

```
