<?php
class MyFirstPersistentSoapServer {
private $resource; // (Such as PDO, mysqli, etc..)
public $myvar1;
public $myvar2;
public function __construct() {
$this->__wakeup(); // We're calling our wakeup to handle starting our resource
}
public function __wakeup() {
$this->resource = CodeToStartOurResourceUp();
}
public function __sleep() {
// We make sure to leave out $resource here, so our session data remains persistent
// Failure to do so will result in the failure during the unserialization of data
// on the next request; thus, our SoapObject would not be persistent across requests.
return array('myvar1','myvar2');
}
}
try {
session_start();
$server = new SoapServer(null, array('uri' => $_SERVER['REQUEST_URI']));
$server->setClass('MyFirstPersistentSoapServer');
// setPersistence MUST be called after setClass, because setClass's
// behavior sets SESSION_PERSISTENCE_REQUEST upon enacting the method.
$server->setPersistence(SOAP_PERSISTENCE_SESSION);
$server->handle();
} catch(SoapFault $e) {
error_log("SOAP ERROR: ". $e->getMessage());
}
?>