Skip to content
PHP Client library that wraps the Sesame Framework by OpenRDF
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.



Welcome to the phpSesame project, this is a client library for Sesame 2.x which utilises the REST API that it implements.


  • PHP 5+ - (There shouldn't be any subversion dependencies, but I haven't checked thoroughly)
  • HTTP_Request2

This project is a rewrite for Sesame 2.x of the phesame library written by Michele Barbera and Riccardo Giomi.


Unfortunately the project is unsupported, there is some links below that document the library though. Feel free to contact me with any bugs or suggestions though.


I am assuming at this point you have installed and configured Sesame, have a repository set up and the REST API functioning correctly. If not then please consult the Sesame documentation.

Using the Library

To get the library up and running all you need is:

require_once "path/to/phpSesame/phpSesame.php";

$sesame = array('url' => 'http://localhost:8080/openrdf-sesame', 'repository' => 'exampleRepo');
$store = new phpSesame($sesame['url'], $sesame['repository']);

You can change the repository you are working on at any time by calling:


Querying a Store

The simplest way to query a store is:

$sparql = "PREFIX foaf:<>
SELECT ?s ?o WHERE { ?s foaf:name ?o } LIMIT 100";
$resultFormat = phpSesame::SPARQL_XML; // The expected return type, will return a phpSesame_SparqlRes object (Optional)
$lang = "sparql"; // Can also choose SeRQL (Optional)
$infer = true; // Can also choose to explicitly disallow inference. (Optional)

$result = $store->query($sparql, $resultFormat, $lang, $infer);

if($result->hasRows()) {
        foreach($result->getRows() as $row) {
                echo "Subject: " . $row['s'] . ", Object: " . $row['o'] . ".";

The library only supports SPARQL_XML at present, however Sesame supports a number of Content Types and the library could do with some more development.


Sesame 2.x can store commonly used namespaces and associated prefixes so that they do not have to be explicitly defined along with each query; these are held in a repository specific list:

$namespace = $store->getNS("rdf");
$store->setNS("newrdf", $namespace);

Managing Data

Sesame allows you to either to append, overwrite or delete data. You can perform these actions on a specific context or on the entire repository. As such the second parameter is optional but it defaults to all. (I may change this though!):

$index = array("" => array(
    "foaf:name" => array("Joe Bloggs"),
    "foaf:age" => array(21),
    "foaf:knows" => array("")

$conf = array('ns' => array('rdf' => '', 'owl' => ''));
$serializer = ARC2::getRDFXMLSerializer($conf);

$rdfxml = $serializer->getSerializedIndex($index);
$context = ""; // Optional - defaults to entire repository though.
$inputFormat = phpSesame::RDFXML; // Optional - defaults to RDFXML

$store->append($rdfxml, $context, $inputFormat);

Sesame supports a number of input types, the library supports: RDFXML, N3, NTRIPLES, TURTLE, TRIX and TRIG. Please see Sesame's documentation for more information.

This example uses the ARC2 library to provide serialization:

$rdfxml = $serializer->getSerializedIndex($index);
$context = "";

$store->overwrite($rdfxml, $context);

If at a later date you want to modify that data you must recreate the entire data item and overwrite it, unfortunately there is no easier way!

More Information

If you are looking for a good RDF Serializer I use the ARC2 library for managing the data into the format required for this library to use.

API Documentation

Please use PHP Documentor to generate the API documentation.

You can’t perform that action at this time.