PHPackages                             3scale/3scale\_ws\_api\_for\_php - 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. [API Development](/categories/api)
4. /
5. 3scale/3scale\_ws\_api\_for\_php

ActiveLibrary[API Development](/categories/api)

3scale/3scale\_ws\_api\_for\_php
================================

Client for 3scale web service management system API

v2.7.1(9y ago)3215.7k↓45.7%15[1 issues](https://github.com/3scale/3scale_ws_api_for_php/issues)1MITPHPPHP &gt;=5.3

Since Aug 27Pushed 9y ago41 watchersCompare

[ Source](https://github.com/3scale/3scale_ws_api_for_php)[ Packagist](https://packagist.org/packages/3scale/3scale_ws_api_for_php)[ Docs](https://support.3scale.net/libraries)[ RSS](/packages/3scale-3scale-ws-api-for-php/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (2)DependenciesVersions (4)Used By (1)

Client for 3scale Web Service Management API [![Build Status](https://camo.githubusercontent.com/d665c6638acc74bda3aa80fe14950162ade1e91567242b1e2479d2bd7409c6e5/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f337363616c652f337363616c655f77735f6170695f666f725f7068702e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/3scale/3scale_ws_api_for_php)
=============================================================================================================================================================================================================================================================================================================================================================================

[](#client-for-3scale-web-service-management-api-)

3scale integration plugin for PHP applications. 3scale is an API Infrastructure service which handles API Keys, Rate Limiting, Analytics, Billing Payments and Developer Management. Includes a configurable API dashboard and developer portal CMS. More product stuff at , support information at .

### Tutorials

[](#tutorials)

- Plugin Setup:
- Rate Limiting:
- Analytics Setup:

Installation
------------

[](#installation)

Download the source code from github: [http://github.com/3scale/3scale\_ws\_api\_for\_php](http://github.com/3scale/3scale_ws_api_for_php) and place it somewhere accessible from your project.

Usage
-----

[](#usage)

Require the ThreeScaleClient.php file (assuming you placed the library somewhere within the include path):

```
require_once('lib/ThreeScaleClient.php')
```

Then create an instance of the client

```
$client = new ThreeScaleClient();
```

> NOTE: unless you specify `ThreeScaleClient();` you will be expected to specify a `provider_key` parameter, which is deprecated in favor of Service Tokens:

```
$client = new ThreeScaleClient("your provider key");
```

Because the object is stateless, you can create just one and store it globally.

Then you can perform calls in the client:

```
$response = $client->authorize("app id", "app key", new ThreeScaleClientCredentials("service id", "service token"));
```

```
$response = $client->report(array(array('app_id' => "app's id"],'usage' => array('hits' => 1))), new ThreeScaleClientCredentials("service id", "service token"));
```

**NOTE:`service_id` is mandatory since November 2016, both when using service tokens and when using provider keys**

### Authorize

[](#authorize)

To authorize a particular application, call the `authorize` method passing it the `application id` and `service id` and optionally the application key:

```
$response = $client->authorize("app id", "app key", new ThreeScaleClientCredentials("service id", "service token"));
```

If you had configured a (deprecated) provider key, you would instead use:

```
$response = $client->authorize("the app id", "the app key", "service id"));
```

Then call the `isSuccess()` method on the returned object to see if the authorization was successful:

```
if ($response->isSuccess()) {
  // All fine, proceeed.
} else {
  // Something's wrong with this app.
}
```

If both provider and app id are valid, the response object contains additional information about the status of the application:

```
//Returns the name of the plan the application is signed up to.
$response->getPlan()
```

If the plan has defined usage limits, the response contains details about the usage broken down by the metrics and usage limit periods.

```
// The usageReports array contains one element per each usage limit defined on the plan.
$usageReports = $response->getUsageReports();
$usageReport  = $usageReports[0];

// The metric
$usageReport->getMetric() // "hits"

// The period the limit applies to
$usageReport->getPeriod()       // "day"
$usageReport->getPeriodStart()  // 1272405600 (Unix timestamp for April 28, 2010, 00:00:00)
$usageReport->getPeriodEnd()    // 1272492000 (Unix timestamp for April 29, 2010, 00:00:00)

// The current value the application already consumed in the period
$usageReport->getCurrentValue() // 8032

// The maximal value allowed by the limit in the period
$usageReport->getMaxValue()     // 10000

// If the limit is exceeded, this will be true, otherwise false:
$usageReport->isExceeded()      // false
```

If the authorization failed, the `getErrorCode()` returns system error code and `getErrorMessage()` human readable error description:

```
$response->getErrorCode()       // "usage_limits_exceeded"
$response->getErrorMessage()    // "Usage limits are exceeded"
```

### Authrep

[](#authrep)

To authorize a particular application, call the `authrep` method passing it the `application id` and `service id` and optionally the application key:

```
$response = $client->authrep("app id", "app key", new ThreeScaleClientCredentials("service id", "service token"), array('hits' => 1));
```

Then call the `isSuccess()` method on the returned object to see if the authorization was successful:

```
if ($response->isSuccess()) {
  // All fine, proceeed.
} else {
  // Something's wrong with this app.
}
```

If both provider and app id are valid, the response object contains additional information about the status of the application:

```
//Returns the name of the plan the application is signed up to.
$response->getPlan()
```

You can also use other patterns such as `user_key` mode during the authrep call

```
$response = $client->authrep_with_user_key("user_key", new ThreeScaleClientCredentials("service id", "service token"), array('hits' => 1));
```

### Report

[](#report)

To report usage, use the `report` method. You can report multiple transaction at the same time:

```
$response = $client->report(array(
      array('app_id' => "first app's id",'usage' => array('hits' => 1)),
      array('app_id' => "second app's id", 'usage' => array('hits' => 1))), new ThreeScaleClientCredentials("service id", "service token"));
```

The `"app_id"`, `"usage"` parameters are required alongiwth `service id` and `service token`. Additionaly, you can specify a timestamp of the transaction:

```
$response = $client->report(array(
  array('app_id'    => "app's id",
        'usage'     => array('hits' => 1),
        'timestamp' => mktime(12, 36, 0, 4, 28, 2010, new ThreeScaleClientCredentials("service id", "service token")));
```

The timestamp can be either an unix timestamp (as integer) or a string. The string has to be in a format parseable by the [strtotime](http://php.net/manual/en/function.strtotime.php) function. For example:

```
"2010-04-28 12:38:33 +0200"
```

If the timestamp is not in UTC, you have to specify a time offset. That's the "+0200" (two hours ahead of the Universal Coordinate Time) in the example above.

Then call the `isSuccess()` method on the returned response object to see if the report was successful:

```
if ($response->isSuccess()) {
  // All OK.
} else {
  // There was an error.
}
```

In case of error, the `getErrorCode()` returns system error code and `getErrorMessage()`human readable error description:

```
$response->getErrorCode()    // "provider_key_invalid"
$response->getErrorMessage() // "provider key \"foo\" is invalid"
```

Custom backend for the 3scale Service Management API
----------------------------------------------------

[](#custom-backend-for-the-3scale-service-management-api)

The default URI used for the 3scale Service Management API is . This value can be changed, which is useful when the plugin is used together with the on-premise version of the Red Hat 3scale API Management Platform.

In order to override the URL, pass the `custom URI` while creating instance an instance of the client

```
$client = new ThreeScaleClient(null, "http://custom-backend.example.com:8080");
```

Plugin integration
------------------

[](#plugin-integration)

If you are interested in integrating the plugin with:

- [Composer](http://getcomposer.org/) check [the packagist](https://packagist.org/packages/tdaws/3scale_ws_api_for_php). This is kindly maintained by [daws.ca](http://daws.ca) tech team.
- [Symphony2](http://symfony.com/) check [tonivdv's 3scaleBundle](https://github.com/tonivdv/3scaleBundle). This is kindly maintained by [Adlogix](http://www.adlogix.eu) tech team.

To Test
-------

[](#to-test)

To run tests: `php test/all.php`

Legal
-----

[](#legal)

Copyright (c) 2010 3scale networks S.L., released under the MIT license.

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community27

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~637 days

Total

3

Last Release

3419d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c50e73e664df1271fd854ce6dd132079dd392168dcd6001ca8d7956f2be693fe?d=identicon)[3scale.michal](/maintainers/3scale.michal)

---

Top Contributors

[![solso](https://avatars.githubusercontent.com/u/534518?v=4)](https://github.com/solso "solso (8 commits)")[![madadam](https://avatars.githubusercontent.com/u/5271?v=4)](https://github.com/madadam "madadam (5 commits)")[![isterin](https://avatars.githubusercontent.com/u/41268?v=4)](https://github.com/isterin "isterin (3 commits)")[![tmacedo](https://avatars.githubusercontent.com/u/15672?v=4)](https://github.com/tmacedo "tmacedo (2 commits)")[![avilatusell](https://avatars.githubusercontent.com/u/20283813?v=4)](https://github.com/avilatusell "avilatusell (2 commits)")[![mikz](https://avatars.githubusercontent.com/u/154571?v=4)](https://github.com/mikz "mikz (1 commits)")[![aurelian](https://avatars.githubusercontent.com/u/350?v=4)](https://github.com/aurelian "aurelian (1 commits)")[![SkeletonMan2k21](https://avatars.githubusercontent.com/u/83595790?v=4)](https://github.com/SkeletonMan2k21 "SkeletonMan2k21 (1 commits)")[![thomasmaas](https://avatars.githubusercontent.com/u/54224?v=4)](https://github.com/thomasmaas "thomasmaas (1 commits)")

---

Tags

apimanagement3scaleThreeScale

### Embed Badge

![Health badge](/badges/3scale-3scale-ws-api-for-php/health.svg)

```
[![Health](https://phpackages.com/badges/3scale-3scale-ws-api-for-php/health.svg)](https://phpackages.com/packages/3scale-3scale-ws-api-for-php)
```

###  Alternatives

[planetteamspeak/ts3-php-framework

Modern use-at-will framework that provides individual components to manage TeamSpeak 3 Server instances

21690.9k5](/packages/planetteamspeak-ts3-php-framework)[eveseat/seat

Simple Eve Api Tool

45819.5k](/packages/eveseat-seat)[m165437/laravel-blueprint-docs

API Blueprint Renderer for Laravel

22879.8k](/packages/m165437-laravel-blueprint-docs)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
