SoapServer::setPersistence

(PHP 5, PHP 7, PHP 8)

SoapServer::setPersistenceSets SoapServer persistence mode

Description

public SoapServer::setPersistence(int $mode): void

This function allows changing the persistence state of a SoapServer object between requests. This function allows saving data between requests utilizing PHP sessions. This method only has an affect on a SoapServer after it has exported functions utilizing SoapServer::setClass().

Note:

The persistence of SOAP_PERSISTENCE_SESSION makes only objects of the given class persistent, but not the class static data. In this case, use $this->bar instead of self::$bar.

Note:

SOAP_PERSISTENCE_SESSION serializes data on the class object between requests. In order to properly utilize resources (e.g. PDO), __wakeup() and __sleep() magic methods should be utilized.

Parameters

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 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.

Return Values

No value is returned.

Examples

Example #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());
 }
?>

See Also

Here you can write a comment


Please enter at least 10 characters.
Loading... Please wait.
* Pflichtangabe
There are no comments available yet.

PHP cURL Tutorial: Using cURL to Make HTTP Requests

cURL is a powerful PHP extension that allows you to communicate with different servers using various protocols, including HTTP, HTTPS, FTP, and more. ...

TheMax

Autor : TheMax
Category: PHP-Tutorials

Midjourney Tutorial - Instructions for beginners

There is an informative video about Midjourney, the tool for creating digital images using artificial intelligence, entitled "Midjourney tutorial in German - instructions for beginners" ...

Mike94

Autor : Mike94
Category: KI Tutorials

Basics of views in MySQL

Views in a MySQL database offer the option of creating a virtual table based on the result of an SQL query. This virtual table can be queried like a normal table without changing the underlying data. ...

admin

Autor : admin
Category: mySQL-Tutorials

Publish a tutorial

Share your knowledge with other developers worldwide

Share your knowledge with other developers worldwide

You are a professional in your field and want to share your knowledge, then sign up now and share it with our PHP community

learn more

Publish a tutorial