SoapServer::setPersistence

(PHP 5 >= 5.1.2, PHP 7)

SoapServer::setPersistence — Sets SoapServer persistence mode

Description

publicvoidSoapServer::setPersistence
( int$mode
)

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.

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'); } }

To use multiple instance of services objects, you need to instantiate the classes into objects and use an undocumented SoapServer's method - setObject() to add the service object into the SoapServer object, and handle the service object persistence with $_SESSION instead.

I found that using both modes (SOAP_PERSISTENCE_SESSION and SOAP_PERSISTENCE_REQUEST) cannot be used simultaniously. Because it didn't work at once, I started experimenting by using different settings and as stated below in the comments, "...also use SOAP_PERSISTENCE_REQUEST to save objects between requests" led me to think it was nessecary to use both modes. Well, it might for others, be but for me it turned out a day of freaking out ;) (trying all kinds of session stuff, etc etc).Also, if persistence doesn't work, please check if session_start() is called somewhere in the script and try not to call it twice or whatsoever: it won't work...

I had some issues getting session persistence (SOAP_PERSISTENCE_SESSION) to work. I finally got it working after setting session.auto_start=0, and then only calling session_start() in the script containing the SoapServer. Maybe this is obvious, but took me a bit to figure it out.

I only tried it with session.use_cookies=1, so if the settings above don't work for you, make sure cookies are enabled, though it may work without the need for cookies.

When using "SoapServer::setPersistence( SOAP_PERSISTENCE_SESSION )", you apparently MUST include the class that was used in "SoapServer::setClass()" BEFORE any "session_*" commands.

I found this out using "__autoload()" and a whole lot of "syslog()"; it kept failing to include the class that I was using for my soap server, but that class is ONLY ever referenced by the page itself, and even then only for the purposes of setting the class for the soap server; none of my code would ever cause it to autoload. The problem was that I was including my session-handling code first.

If the session gets started BEFORE the page defines the class definition, then persistence CANNOT happen.

The order should be:1. Include the class for use with the soap server.2. Start up your session.3. Set up your soap server.4. Handle your soap request.