PHPackages                             sag/sag - 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. [Database &amp; ORM](/categories/database)
4. /
5. sag/sag

AbandonedArchivedLibrary[Database &amp; ORM](/categories/database)

sag/sag
=======

A simple but powerful PHP library for talking to CouchDB.

v0.9.0(12y ago)15039.3k—2.8%51[1 PRs](https://github.com/sbisbee/sag/pulls)Apache-2.0PHPPHP &gt;=5.2.0

Since Oct 11Pushed 4y ago9 watchersCompare

[ Source](https://github.com/sbisbee/sag)[ Packagist](https://packagist.org/packages/sag/sag)[ Docs](http://www.saggingcouch.com/)[ RSS](/packages/sag-sag/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (7)Used By (0)

Sag
===

[](#sag)

Note: I have not maintained this project for years since I no longer use CouchDB or PHP. I assume it still works with CouchDB, but haven't been active in the community for a while and won't be testing or responding to tickets.

Version %VERSION%

Sag is a PHP library for working with CouchDB. It is designed to not force any particular programming method on its users - you just pass PHP objects, and get stdClass objects and Exceptions back. This makes it trivial to incorporate Sag into your application, build different functionality on top of it, and expand Sag to incorporate new CouchDB functionality.

Compatability
-------------

[](#compatability)

Each Sag release is tested with an automated testing suite against all the combinations of:

- PHP 5.5.x
- CouchDB 1.6.x
- Cloudant

Lower versions of CouchDB and PHP will likely work with Sag, but they are not officially supported, so your mileage may vary.

If you are running pre-1.5.1 CouchDB (important security fix) or pre-5.3 PHP, then you probably want to look into updating your environment.

Error Handling
--------------

[](#error-handling)

Sag's paradigm of simplicity is carried into its error handling by allowing you to send data to CouchDB that will result in errors (ex., malformed JSON). This is because CouchDB knows when there is an error better than Sag. This also makes Sag more future proof, instead of worrying about each of CouchDB's API changes. Therefore, Sag will only look for PHP interface problems and issues that are native to PHP, such as passing an int instead of a stdClass.

All errors are floated back to your application with Exceptions. Sag does not catch any errors itself, allowing your application to care about them or not.

There are two types of exceptions:

SagException For errors that happen within Sag, such as an invalid type being passed to a function or being unable to open a socket to the server.

SagCouchException For errors generated by CouchDB (ex., if you pass it invalid JSON). The CouchDB error message will be put into the Exception's message (`$e->getMessage()`) and the HTTP status code will be the exception's code (`$e->getCode()`).

You can catch these two types of exceptions explicitly, allowing you to split your error handling depending on where the error occurred, or implicitly by simply catching the Exception class.

Networking
----------

[](#networking)

Sag allows you to specify the HTTP library you want to use when communicating with CouchDB. The supported libraries are:

- cURL (`Sag::$CURL_HTTP_ADAPTER`) - has functionality that native sockets do not support, such as SSL. Used by default.
- Native sockets (`Sag::$NATIVE_HTTP_ADAPTER`). Prevent dependencies, such as cURL, that shared environments may not support.

You can choose which library you want Sag to use by calling the `setHTTPAdapter()` function and passing it the appropriate variable.

If you want to monitor your application's activity on the server side (ex., if you are proxying requests to CouchDB through a web server), then examine the HTTP User-Agent header.

Results
-------

[](#results)

When you have told Sag to decode CouchDB's responses (the default setting), they are stored in an object, breaking out the HTTP header lines and data. For example, running `print_r($sag->get('/1'));` (where '/1' is the location of a document) would give you something like this:

```
(
    [headers] => stdClass Object
        (
            [_HTTP] => stdClass Object
                (
                    [raw] => HTTP/1.1 200 OK
                    [version] => 1.1
                    [status] => 200
                )

            [server] => CouchDB/1.5.0 (Erlang OTP/R15B01)
            [etag] => "1-967a00dff5e02add41819138abb3284d"
            [date] => Sat, 30 Nov 2013 20:39:43 GMT
            [content-type] => application/json
            [content-length] => 87
            [cache-control] => must-revalidate
        )

    [body] => stdClass Object
        (
            [_id] => 7c23517e0faa1af2786d27e2ae095552
            [_rev] => 1-967a00dff5e02add41819138abb3284d
        )

    [status] => 200
)

```

HTTP protocol information is stored in $result-&gt;headers, its headers broken out as entries in the headers array - the "\_HTTP" array element holds the basic HTTP information in raw form (`$result->headers->_HTTP->raw)`, and then broken out into HTTP version number (`$result->headers->_HTTP->version`) and status code (`$result->headers->_HTTP->status`). The status code is also stored at the top of the response object (`$result->status`).

The `$result->body` property holds the raw data from CouchDB, which you can have Sag automatically decode into PHP objects with `json_decode()`.

The `$result->body` property holds the response body (usually JSON), which Sag will automatically decode with `json_decode()` when the content-type is 'application/json'.

If you've told Sag to not decode CouchDB's responses, then it'll only return the resulting JSON from CouchDB as a string (what would have been in the body property if you had set decode to true). None of the HTTP info is included.

If CouchDB specifies Set-Cookies, then they will be stored in `$result->cookies`as a stdClass.

Functions
---------

[](#functions)

Detailed documentation of the functions and API are available at .

License
-------

[](#license)

Sag is released under the Apache License, version 2.0. See the file named LICENSE for more information.

Copyright information is in the NOTICE file.

More?
-----

[](#more)

See  for more detailed information, bug reporting, planned features, etc.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity46

Moderate usage in the ecosystem

Community25

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.4% of commits — single point of failure

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

Unknown

Total

1

Last Release

4526d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e868bdebaab27d8474e6b4558226b889c3d62b7b7ba1c6f9beae7d620d699dcb?d=identicon)[sbisbee](/maintainers/sbisbee)

---

Top Contributors

[![sbisbee](https://avatars.githubusercontent.com/u/81002?v=4)](https://github.com/sbisbee "sbisbee (457 commits)")[![BigBlueHat](https://avatars.githubusercontent.com/u/43209?v=4)](https://github.com/BigBlueHat "BigBlueHat (12 commits)")[![jimt](https://avatars.githubusercontent.com/u/180326?v=4)](https://github.com/jimt "jimt (2 commits)")[![nullvariable](https://avatars.githubusercontent.com/u/171515?v=4)](https://github.com/nullvariable "nullvariable (1 commits)")[![pkruithof](https://avatars.githubusercontent.com/u/330828?v=4)](https://github.com/pkruithof "pkruithof (1 commits)")[![pquentin](https://avatars.githubusercontent.com/u/42327?v=4)](https://github.com/pquentin "pquentin (1 commits)")[![rwos](https://avatars.githubusercontent.com/u/747372?v=4)](https://github.com/rwos "rwos (1 commits)")[![sloonz](https://avatars.githubusercontent.com/u/142145?v=4)](https://github.com/sloonz "sloonz (1 commits)")[![timjuravich](https://avatars.githubusercontent.com/u/428293?v=4)](https://github.com/timjuravich "timjuravich (1 commits)")[![bradley-holt](https://avatars.githubusercontent.com/u/89264?v=4)](https://github.com/bradley-holt "bradley-holt (1 commits)")[![dave-cz](https://avatars.githubusercontent.com/u/4918852?v=4)](https://github.com/dave-cz "dave-cz (1 commits)")

### Embed Badge

![Health badge](/badges/sag-sag/health.svg)

```
[![Health](https://phpackages.com/badges/sag-sag/health.svg)](https://phpackages.com/packages/sag-sag)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90440.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)[wildside/userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)

PHPackages © 2026

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