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

v0.3.2 2016-06-11 22:07 UTC


Build Status Coverage Status Code Quality Latest Stable Version Total Downloads

Simple PHP package for making Search/Retrieve via URL (SRU) requests, using the Guzzle HTTP client and returning QuiteSimpleXMLElement instances. Includes an iterator to easily iterate over search 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 package.

Install using Composer

Add the package to the require list of your composer.json file.

    "require": {
        "scriptotek/sru-client": "dev-master"

and run composer install to get the latest version of the package.

Laravel 5 integration

In the $providers array add the service providers for this package:


Add the facade of this package to the $aliases array:

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

Publish configuration in Laravel 5:

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

The configuration file is copied to config/sru.php.


use Scriptotek\Sru\Client as SruClient;

$url = '';

$client = new SruClient($url, array(
    'schema' => 'marcxml',
    'version' => '1.1',
    'user-agent' => 'MyTool/0.1'

To get the first record matching a query:


The result is a Record object, or null if not found.

To iterate over all the results from a searchRetrieve query, use the Records object returned from Client::records(). The first argument is the CQL query, and the second optional argument is the number of records to fetch for each request (defaults to 10).

$records = $client->records('dc.title="Hello world"');
if ($records->error) {
    print 'ERROR: ' . $records->error . "\n";
foreach ($records as $record) {
    echo "Got record " . $record->position . " of " . $records->numberOfRecords() . "\n";
    // processRecord($record->data);
Use explain to get information about servers:
$urls = array(

foreach ($urls as $url) {

    $client = new SruClient($url, array(
        'version' => '1.1',
        'user-agent' => 'MyTool/0.1'

    $response = $client->explain();

    if ($response->error) {
        print 'ERROR: ' . $response->error . "\n";

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


API documentation

API documentation can be generated using e.g. Sami, which is included in the dev requirements of composer.json.

php vendor/bin/sami.php update sami.config.php -v

You can view it at