(PHP 5 >= 5.1.2)
SoapServer::setPersistence — Define el modo persistente para el SoapServer
$mode
)Esta función permite cambiar el estado del modo persistente de un objeto SoapServer entre peticiones. Esta función permite guardar datos entre peticiones usando sesiones de PHP. Este método solo tiene un efecto en el SoapServer depués de que se hayan exportado funciones usando SoapServer::setClass().
Nota:
La persistencia de
SOAP_PERSISTENCE_SESSION
solamente hace que los objectos de la clase dada sean persistentes pero no los datos de la clase estática. En este caso utilice $this->bar en lugar de self::$bar.
Nota:
SOAP_PERSISTENCE_SESSION
serializa de la clase objecto entre peticionesserializes data on the class object between requests. In order to properly utilize resources (e.g. PDO), __wakeup() and __sleep() magic methods should be utilized.
mode
One of the SOAP_PERSISTENCE_XXX constants.
SOAP_PERSISTENCE_REQUEST
- SoapServer data does not persist between
requests. This is the default behavior of any SoapServer
object after setClass is called.
SOAP_PERSISTENCE_SESSION
- SoapServer data does persists between requests.
This is accomplished by serializing the SoapServer class data into $_SESSION['_bogus_session_name'],
because of this session_start() must be called before this persistence mode is set.
No devuelve ningún valor.
Ejemplo #1 SoapServer::setPersistence() example
<?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());
}
?>