Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
YAZ Functions

CLXXXIII. YAZ Functions

Introduction

This extension offers a PHP interface to the YAZ toolkit that implements the Z39.50 Protocol for Information Retrieval. With this extension you can easily implement a Z39.50 origin (client) that searches or scans Z39.50 targets (servers) in parallel.

The module hides most of the complexity of Z39.50 so it should be fairly easy to use. It supports persistent stateless connections very similar to those offered by the various RDB APIs that are available for PHP. This means that sessions are stateless but shared among users, thus saving the connect and initialize phase steps in most cases.

YAZ is available at http://www.indexdata.dk/yaz/. You can find news information, example scripts, etc. for this extension at http://www.indexdata.dk/phpyaz/.

Note: This extension has been moved to the PECL repository and is no longer bundled with PHP as of PHP 5.0.0.

Installation

Obtain YAZ (ANSI/NISO Z39.50 support) and install it. YAZ can be fetched in source or in various prebuilt packages from the YAZ archive. Systems such as Debian GNU/Linux, Suse Linux, FreeBSD also has YAZ as part of their distribution.

For the PHP 4 series, the YAZ extension is bundled (but not YAZ itself) Build PHP with your favorite modules and add option --with-yaz[=DIR].

Example 1. YAZ compilation for PHP 4 on Unix

gunzip -c php-4.4.X.tar.gz|tar xf -
gunzip -c yaz-2.1.8.tar.gz|tar xf -
cd yaz-2.1.8
./configure --prefix=/usr
make
sudo make install
cd ../php-4.4.X.
./configure --with-yaz=/usr/bin
make
sudo make install

For PHP 5, the YAZ extension is in PECL and is installed as a shared object/dll. If you have pear installed the easiest way to download, configure and install the YAZ extension is by using the pear command.

Example 2. Installation of PECL YAZ on GNU/Debian Linux

On a Debian GNU/Linux system the following installs YAZ and PECL YAZ:

sudo apt-get install libyaz-dev
sudo pear install yaz

On Windows, php_yaz.dll depend on yaz.dll. The yaz.dll is part of the Win32 ZIP from the PHP site. It is also part of the Windows YAZ install available from the YAZ WIN32 area.

Warning

The PHP 5.0.5 Win32 zip includes a too old version of yaz.dll (version 1.9.1 < required version 2.0.13). If that's the case use the yaz.dll from a newer YAZ WIN32 install.

On windows, don't forget to add the PHP directory to the PATH, so that the yaz.dll file can be found by the system.

If you are using YAZ as a shared extension, add (or uncomment) the following line in php.ini on Unix:
extension=yaz.so
And for Windows:
extension=php_yaz.dll

Warning

The IMAP, recode, YAZ and Cyrus extensions cannot be used in conjuction, because they both share the same internal symbol.

Note: The above problem is solved in version 2.0 of YAZ.

Runtime Configuration

The behaviour of these functions is affected by settings in php.ini.

Table 1. YAZ configuration options

NameDefaultChangeableChangelog
yaz.max_links"100"PHP_INI_ALLAvailable since PHP 4.3.0.
yaz.log_fileNULLPHP_INI_ALLAvailable since PHP 4.3.0.
For further details and definitions of the PHP_INI_* constants, see the Appendix G.

Resource Types

This extension has no resource types defined.

Predefined Constants

This extension has no constants defined.

Examples

PHP/YAZ keeps track of connections with targets (Z-Associations). A resource represents a connection to a target.

The script below demonstrates the parallel searching feature of the API. When invoked with no arguments it prints a query form; else (arguments are supplied) it searches the targets as given in array host.

Example 3. Parallel searching using Yaz

&#60;?php
$host=$_REQUEST[host];
$query=$_REQUEST[query];
$num_hosts = count($host);
if (empty($query) || count($host) == 0) {
    echo '&#60;form method="get"&#62;
    &#60;input type="checkbox"
    name="host[]" value="bagel.indexdata.dk/gils" /&#62;
        GILS test
    &#60;input type="checkbox"
    name="host[]" value="localhost:9999/Default" /&#62;
        local test
    &#60;input type="checkbox" checked="checked"
    name="host[]" value="z3950.loc.gov:7090/voyager" /&#62;
        Library of Congress
    &#60;br /&#62;
    RPN Query:
    &#60;input type="text" size="30" name="query" /&#62;
    &#60;input type="submit" name="action" value="Search" /&#62;
    &#60;/form&#62;
    ';        
} else {
    echo 'You searched for ' . htmlspecialchars($query) . '&#60;br /&#62;';
    for ($i = 0; $i &#60; $num_hosts; $i++) {
        $id[] = yaz_connect($host[$i]);
    yaz_syntax($id[$i], "usmarc");
        yaz_range($id[$i], 1, 10);
        yaz_search($id[$i], "rpn", $query);
    }
    yaz_wait();
    for ($i = 0; $i &#60; $num_hosts; $i++) {
        echo '&#60;hr /&#62;' . $host[$i] . ':';
        $error = yaz_error($id[$i]);
        if (!empty($error)) {
            echo "Error: $error";
        } else {
            $hits = yaz_hits($id[$i]);
            echo "Result Count $hits";
        }
        echo '&#60;dl&#62;';
        for ($p = 1; $p &#60;= 10; $p++) {
            $rec = yaz_record($id[$i], $p, "string");
            if (empty($rec)) continue;
            echo "&#60;dt&#62;&#60;b&#62;$p&#60;/b&#62;&#60;/dt&#62;&#60;dd&#62;";
            echo nl2br($rec);
            echo "&#60;/dd&#62;";
        }
        echo '&#60;/dl&#62;';
    }
}
?&#62;

Table of Contents
yaz_addinfo -- Returns additional error information
yaz_ccl_conf -- Configure CCL parser
yaz_ccl_parse -- Invoke CCL Parser
yaz_close -- Close YAZ connection
yaz_connect --  Prepares for a connection to a Z39.50 server
yaz_database --  Specifies the databases within a session
yaz_element --  Specifies Element-Set Name for retrieval
yaz_errno -- Returns error number
yaz_error -- Returns error description
yaz_es_result --  Inspects Extended Services Result
yaz_es --  Prepares for an Extended Service Request
yaz_get_option -- Returns value of option for connection
yaz_hits -- Returns number of hits for last search
yaz_itemorder --  Prepares for Z39.50 Item Order with an ILL-Request package
yaz_present --  Prepares for retrieval (Z39.50 present)
yaz_range --  Specifies a range of records to retrieve
yaz_record -- Returns a record
yaz_scan_result -- Returns Scan Response result
yaz_scan -- Prepares for a scan
yaz_schema --  Specifies schema for retrieval
yaz_search -- Prepares for a search
yaz_set_option -- Sets one or more options for connection
yaz_sort -- Sets sorting criteria
yaz_syntax --  Specifies the preferred record syntax for retrieval
yaz_wait -- Wait for Z39.50 requests to complete