A PHP REST client library for www.ably.io, the realtime messaging service. This library currently targets the Ably 1.1 client library specification. You can jump to the 'Known Limitations' section to see the features this client library does not yet support or view our client library SDKs feature support matrix to see the list of all the available features.
This SDK supports PHP 5.6 and 7.0+
We regression-test the library against a selection of PHP versions (which will change over time, but usually consists of the versions that are supported upstream). Please refer to .travis.yml for the set of versions that currently undergo CI testing.
We'll happily support (and investigate reported problems with) any reasonably-widely-used PHP version. If you find any compatibility issues, please do raise an issue in this repository or contact Ably customer support for advice.
Currently, this SDK only supports Ably REST. However, you can use the MQTT adapter to implement Ably's Realtime features using Python.
This SDK is not compatible with some of the Ably features:
Feature |
---|
Remember fallback host during failures |
MsgPack Binary Protocol |
Visit https://www.ably.io/documentation for a complete API reference and more examples.
The client library is available as a composer package on packagist. If you don't have composer already installed, you can get it from https://getcomposer.org/.
Install Ably from the shell with:
$ composer require ably/ably-php --update-no-dev
Then simply require composer's autoloader:
require_once __DIR__ . '/vendor/autoload.php';
Clone or download Ably from this repo and require ably-loader.php
:
require_once __DIR__ . '/ably-php/ably-loader.php';
All examples assume a client and/or channel has been created as follows:
$client = new Ably\AblyRest('your.appkey:xxxxxx');
$channel = $client->channel('test');
$channel->publish('myEvent', 'Hello!'); // => true
$messagesPage = $channel->history(); // => \Ably\Models\PaginatedResult
$messagesPage->items[0]; // => \Ably\Models\Message
$messagesPage->items[0]->data; // payload for the message
$messagesPage->next(); // retrieves the next page => \Ably\Models\PaginatedResult
$messagesPage->hasNext(); // false, there are no more pages
$membersPage = $channel->presence->get(); // => \Ably\Models\PaginatedResult
$membersPage->items[0]; // first member present in this page => \Ably\Models\PresenceMessage
$membersPage->items[0]->clientId; // client ID of first member present
$membersPage->next(); // retrieves the next page => \Ably\Models\PaginatedResult
$membersPage->hasNext(); // false, there are no more pages
$presencePage = $channel->presence->history(); // => \Ably\Models\PaginatedResult
$presencePage->items[0]; // => \Ably\Models\PresenceMessage
$presencePage->items[0]->clientId; // client ID of first member
$presencePage->next(); // retrieves the next page => \Ably\Models\PaginatedResult
$tokenDetails = $client->auth->requestToken();
// => \Ably\Models\PresenceMessage
$tokenDetails->token; // => "xVLyHw.CLchevH3hF....MDh9ZC_Q"
$client = new Ably\AblyRest( $tokenDetails->token );
// or
$client = new Ably\AblyRest( array( 'tokenDetails' => $tokenDetails ) );
$token = $client->auth->createTokenRequest();
// => {"id" => ...,
// "clientId" => null,
// "ttl" => 3600,
// "timestamp" => ...,
// "capability" => "{\"*\":[\"*\"]}",
// "nonce" => ...,
// "mac" => ...}
$statsPage = client->stats(); // => \Ably\Models\PaginatedResult
$statsPage->items[0]; // => \Ably\Models\Stats
$statsPage->next(); // retrieves the next page => \Ably\Models\PaginatedResult
$client->time(); // in milliseconds => 1430313364993
If you're using Laravel, you may want to check out ably-php-laravel wrapper, which is a wrapper with Laravel-specific helper classes.
Please visit http://support.ably.io/ for access to our knowledgebase and to ask for any assistance.
You can also view the community reported Github issues.
To see what has changed in recent versions of Bundler, see the CHANGELOG.
- This client library requires PHP version 5.4 or greater
- msgpack support is currently missing in PHP client library, as there is no stable PHP msgpack library available.
The client library uses the Ably sandbox environment to provision an app and run the tests against that app. In order to run the tests, you need to:
git clone https://github.com/ably/ably-php.git
cd ably-php
composer install
git submodule init
git submodule update
./vendor/bin/phpunit
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Ensure you have added suitable tests and the test suite is passing (run
vendor/bin/phpunit
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
This library uses semantic versioning. For each release, the following needs to be done:
- Update the version number in src/AblyRest.php
- Run
github_changelog_generator
to automate the update of the CHANGELOG. Once theCHANGELOG
update has completed, manually change theUnreleased
heading and link with the current version number such as1.0.0
. Also ensure that theFull Changelog
link points to the new version tag instead of theHEAD
. - Commit
- Add a tag and push to origin such as
git tag 1.0.0 && git push origin 1.0.0
- Visit https://github.com/ably/ably-php/tags and add release notes for the release including links to the changelog entry.
- Visit https://packagist.org/packages/ably/ably-php, log in to Packagist, and click the "Update" button.
- Remember to release an update for the PHP Laravel library