PHPackages                             scriptotek/sru-client - 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. [Search &amp; Filtering](/categories/search)
4. /
5. scriptotek/sru-client

ActiveLibrary[Search &amp; Filtering](/categories/search)

scriptotek/sru-client
=====================

Package for making Search/Retrieve via URL requests and parse the responses

v0.7.2(4y ago)196.4k↓50%3[4 issues](https://github.com/scriptotek/php-sru-client/issues)1MITPHP

Since Apr 26Pushed 2y ago4 watchersCompare

[ Source](https://github.com/scriptotek/php-sru-client)[ Packagist](https://packagist.org/packages/scriptotek/sru-client)[ Docs](http://github.com/scriptotek/sru-client)[ RSS](/packages/scriptotek-sru-client/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (9)Versions (20)Used By (1)

[![Coverage](https://camo.githubusercontent.com/68d601e417858fef89fe596fe3629cf37e3d356c5b593c29888b159d36d780d2/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f7363726970746f74656b2f7068702d7372752d636c69656e742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/gh/scriptotek/php-sru-client)[![Code Quality](https://camo.githubusercontent.com/b6b2336974bc2258e1acec7eef097cbc60cb0adfdebd56fd737cd6d8927c75a4/687474703a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7363726970746f74656b2f7068702d7372752d636c69656e742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/scriptotek/php-sru-client/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/f973f1762f092853a3ad1bd79acd0219056709fe4afa1db61460c862c437dc6c/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7363726970746f74656b2f7372752d636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/scriptotek/sru-client)[![Total Downloads](https://camo.githubusercontent.com/c38fed10af0484271d60fcc7c816cd3fcbdc8ccad171e9ec9f0017057437072d/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7363726970746f74656b2f7372752d636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/scriptotek/sru-client)

php-sru-client
==============

[](#php-sru-client)

Simple PHP package for making [Search/Retrieve via URL](http://www.loc.gov/standards/sru/) (SRU) requests and returning [QuiteSimpleXMLElement](//github.com/danmichaelo/quitesimplexmlelement) objects. The response object is an iterator, to support easy iteration over the results, abstracting away the process of making multiple requests.

If you prefer a simple text response, you might have a look at the [php-sru-search](https://github.com/Zeitschriftendatenbank/php-sru-search) package.

Install using Composer
----------------------

[](#install-using-composer)

Use [Composer](https://getcomposer.org) to install sru-client with a HTTP library such as Guzzle:

```
composer require scriptotek/sru-client php-http/guzzle6-adapter http-interop/http-factory-guzzle
```

We use [HTTP discovery](https://github.com/http-interop/http-factory-discovery) to discover [HTTP client](https://packagist.org/providers/psr/http-client-implementation) and [HTTP factory](https://packagist.org/providers/psr/http-factory-implementation) implementations, so Guzzle can be swapped with any other [PSR-17](https://www.php-fig.org/psr/psr-17/)/[PSR-18](https://www.php-fig.org/psr/psr-18/)-compatible library.

Configuring the client
----------------------

[](#configuring-the-client)

```
require_once('vendor/autoload.php');
use Scriptotek\Sru\Client as SruClient;

$sru = new SruClient('http://bibsys-network.alma.exlibrisgroup.com/view/sru/47BIBSYS_NETWORK', [
    'schema' => 'marcxml',
    'version' => '1.2',
    'user-agent' => 'MyTool/0.1',
]);
```

Search and retrieve
-------------------

[](#search-and-retrieve)

To get all the records matching a given CQL query:

```
$records = $sru->all('alma.title="Hello world"');
foreach ($records as $record) {
	echo "Got record " . $record->position . " of " . $records->numberOfRecords() . "\n";
	// processRecord($record->data);
}
```

where `$record` is an instance of [Record](//scriptotek.github.io/php-sru-client/api_docs/Scriptotek/Sru/Record.html) and `$record->data` is an instance of [QuiteSimpleXMLElement](https://github.com/danmichaelo/quitesimplexmlelement).

The `all()` method takes care of continuation for you under the hood for you; the [Records](//scriptotek.github.io/php-sru-client/api_docs/Scriptotek/Sru/Records.html) generator continues to fetch records until the result set is depleted. A default batch size of 10 is used, but you can give any number supported by the server as a second argument to the `all()` method.

If you query for some identifier, you can use the convenience method `first()`:

```
$record = $sru->first('alma.isbn="0415919118"');
```

The result is a [Record](//scriptotek.github.io/php-sru-client/api_docs/Scriptotek/Sru/Record.html)object, or `null` if not found.

Use explain to get information about servers
--------------------------------------------

[](#use-explain-to-get-information-about-servers)

```
$urls = array(
    'http://sru.bibsys.no/search/biblio',
    'http://lx2.loc.gov:210/LCDB',
    'http://services.d-nb.de/sru/zdb',
    'http://api.libris.kb.se/sru/libris',
);

foreach ($urls as $url) {

    $sru = new SruClient($url, [
        'version' => '1.1',
        'user-agent' => 'MyTool/0.1'
    ]);

    try {
        $response = $sru->explain();
    } catch (\Scriptotek\Sru\Exceptions\SruErrorException $e) {
        print 'ERROR: ' . $e->getMessage() . "\n";
        continue;
    }

    printf("Host: %s:%d\n", $response->host, $response->port);
    printf("  Database: %s\n", $response->database->identifier);
    printf("  %s\n", $response->database->title);
    printf("  %s\n", $response->database->description);
    print "  Indexes:\n";
    foreach ($response->indexes as $idx) {
        printf("   - %s: %s\n", $idx->title, implode(' / ', $idx->maps));
    }

}
```

Laravel 5 integration
---------------------

[](#laravel-5-integration)

Add the service provider to the `'providers'` array in `config/app.php`:

```
Scriptotek\Sru\Providers\SruServiceProvider::class,

```

Optionally, add the facade to the `'aliases'` array in the same file:

```
'SruClient'      => Scriptotek\Sru\Facades\SruClient::class,

```

To create the configuration file `config/sru.php`:

```
$ php artisan vendor:publish --provider="Scriptotek\Sru\Providers\SruServiceProvider"

```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 96.5% 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

Every ~155 days

Recently: every ~400 days

Total

19

Last Release

1610d ago

PHP version history (3 changes)v0.4.0PHP ^5.5 || ^7.0

v0.6.0PHP ^5.6 || ^7.0

v0.7.0PHP ^7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/87db1d80793d2adbeca18997c33acbb5cf1dec75ccc5c19f147d666dfbf2e990?d=identicon)[danmichaelo](/maintainers/danmichaelo)

---

Top Contributors

[![danmichaelo](https://avatars.githubusercontent.com/u/434495?v=4)](https://github.com/danmichaelo "danmichaelo (109 commits)")[![S1SYPHOS](https://avatars.githubusercontent.com/u/12161504?v=4)](https://github.com/S1SYPHOS "S1SYPHOS (1 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")[![sommer-gei](https://avatars.githubusercontent.com/u/29099046?v=4)](https://github.com/sommer-gei "sommer-gei (1 commits)")[![u2Silvar](https://avatars.githubusercontent.com/u/36190070?v=4)](https://github.com/u2Silvar "u2Silvar (1 commits)")

---

Tags

code4libsru-clientsru

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/scriptotek-sru-client/health.svg)

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

###  Alternatives

[openai-php/client

OpenAI PHP is a supercharged PHP API client that allows you to interact with the Open AI API

5.8k22.6M232](/packages/openai-php-client)[opensearch-project/opensearch-php

PHP Client for OpenSearch

15024.3M65](/packages/opensearch-project-opensearch-php)[typesense/typesense-php

PHP client for Typesense Search Server: https://github.com/typesense/typesense

2625.6M69](/packages/typesense-typesense-php)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[friendsofsymfony/http-cache

Tools to manage HTTP caching proxies with PHP

36114.7M36](/packages/friendsofsymfony-http-cache)[deeplcom/deepl-php

Official DeepL API Client Library

2616.2M66](/packages/deeplcom-deepl-php)

PHPackages © 2026

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