PHPackages                             tdaws/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. tdaws/3scale\_ws\_api\_for\_php

ActiveLibrary[API Development](/categories/api)

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

3scale integration plugin for PHP applications - with composer.json

063.1k2PHP

Since Aug 28Pushed 12y ago2 watchersCompare

[ Source](https://github.com/tdaws/3scale_ws_api_for_php)[ Packagist](https://packagist.org/packages/tdaws/3scale_ws_api_for_php)[ RSS](/packages/tdaws-3scale-ws-api-for-php/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Package Deprecated
------------------

[](#package-deprecated)

3Scale has now added composer.json to their repository, so this package is no longer necessary. Please switch over to using their package: "3scale/3scale\_ws\_api\_for\_php": "dev-master"

I will no longer be keeping this package updated.

- Tony Daws

Client for 3scale web service management system 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-system-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 .

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, giving it your provider API key:

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

```

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

### Authorize

[](#authorize)

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

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

```

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"

```

### 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))));

```

The `"app_id"` and `"usage"` parameters are required. 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))));

```

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"

```

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.

Legal
-----

[](#legal)

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

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/6bcbb09d63bdbee45d52f1c22411da2e300ae799931013392f3b92a89ecc75cc?d=identicon)[tdaws](/maintainers/tdaws)

---

Top Contributors

[![solso](https://avatars.githubusercontent.com/u/534518?v=4)](https://github.com/solso "solso (8 commits)")[![tdaws](https://avatars.githubusercontent.com/u/1301631?v=4)](https://github.com/tdaws "tdaws (5 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)")[![SkeletonMan2k21](https://avatars.githubusercontent.com/u/83595790?v=4)](https://github.com/SkeletonMan2k21 "SkeletonMan2k21 (1 commits)")[![aurelian](https://avatars.githubusercontent.com/u/350?v=4)](https://github.com/aurelian "aurelian (1 commits)")

### Embed Badge

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

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

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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