2.2. PHP client modules

In the subdirectory clients/php of the Wolframe installation you'll find the following source files you need. The main module you need to call to establish a session and to issue requests is session.php. The other files are helper classes for the client:

Table 2.2. PHP client modules


implements the Wolframe client/server protocol behind the scenes with a simple interface to send requests to the server and receive the answers.


defines the base class of the connection to a Wolframe server with methods to read and write messages


implements helper functions needed to implement the authentication with the Wolframe-CRAM mech and its password change protocol.


implements the function hash_pbkdf2 available in PHP 5.5. for PHP 5.3. (patch published on php.net)

2.2.1. Example script implementing a request

The script examples/clients/php/webclient_form_xml.php shows the mechanisms of using the PHP client modules to create a client calling Wolframe from a web service. It takes a HTTP request, builds an XML document and a Wolframe server request with this document, passes the request to the server and returns the answer XML to the web client. In case of error an XML with the error message is returned.

2.2.2. Example script for a password change

The script examples/clients/php/webclient_change_password.php shows the changing of password when authenticated with "WOLFRAME-CRAM". It takes a HTTP request, authenticates an initiates a password change. In case of error an XML with the error message is returned.

2.2.3. The session interface

In the following we shortly introduce the Wolframe session interface implemented in clients/php/session.php.

namespace Wolframe
require 'connection.php';
use Wolframe\Connection as Connection;

class Session extends Connection
    /* Constructor
    * @param[in] address Wolframe server IP address to connect
    * @param[in] port Wolframe server port to connect
    * @param[in] sslopt array of PHP options for SSL. The options
    *            are not interpreted, but directly passed to to the SSL
    *            stream context with stream_context_set_option(..)'
    * @param[in] authopt authorization options defining the mechanism
    *            and depending on the mechanism, the credentials needed.
    function __construct( $address, $port, $sslopt, $authmethod);

    /* Change the users password
    * @param[in] the old password
    * @param[in] the new password
    * @remark The function throws in case of an error.
    * @remark The function is blocking on read/write on its connection
    public function changePassword( $oldpassword, $newpassword)

    /* Send a request to the server
    * @param[in] command (optional) identifier prefix of the command
    *            to execute.
    * @param[in] content content of the request (document to process)
    * @return FALSE, if the server reports an error in processing
    *            the request. The error details can be inspected with
    *            lasterror(). In case of success the function returns
    *            the request answer string.
    * @remark The function throws in case of a system or protocol error.
    * @remark The function is blocking on read/write on its connection
    public function request( $command, $content);

    /* Get the last error returned by the Wolframe server (protocol).
    * @return the last error 
    public function lasterror();
} // class Session
} // namespace Wolframe