<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Sets SoapServer persistence mode</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="soapserver.setobject.html">SoapServer::setObject</a></div> <div class="next" style="text-align: right; float: right;"><a href="soapserver.soapserver.html">SoapServer::SoapServer</a></div> <div class="up"><a href="class.soapserver.html">SoapServer</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="soapserver.setpersistence" class="refentry"> <div class="refnamediv"> <h1 class="refname">SoapServer::setPersistence</h1> <p class="verinfo">(PHP 5 >= 5.1.2)</p><p class="refpurpose"><span class="refname">SoapServer::setPersistence</span> — <span class="dc-title">Sets SoapServer persistence mode</span></p> </div> <div class="refsect1 description" id="refsect1-soapserver.setpersistence-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type"><span class="type void">void</span></span> <span class="methodname"><strong>SoapServer::setPersistence</strong></span> ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$mode</code></span> )</div> <p class="para rdfs-comment"> 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 <span class="methodname"><a href="soapserver.setclass.html" class="methodname">SoapServer::setClass()</a></span>. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> The persistence of <strong><code>SOAP_PERSISTENCE_SESSION</code></strong> makes only objects of the given class persistent, but not the class static data. In this case, use <var class="varname"><var class="varname">$this->bar</var></var> instead of self::$bar. </p> </p></blockquote> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> <strong><code>SOAP_PERSISTENCE_SESSION</code></strong> serializes data on the class object between requests. In order to properly utilize resources (e.g. <a href="class.pdo.html" class="classname">PDO</a>), <a href="language.oop5.magic.html#object.wakeup" class="link">__wakeup()</a> and <a href="language.oop5.magic.html#object.sleep" class="link">__sleep()</a> magic methods should be utilized. </p> </p></blockquote> </div> <div class="refsect1 parameters" id="refsect1-soapserver.setpersistence-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">mode</code></em></span> <dd> <p class="para"> One of the <em>SOAP_PERSISTENCE_XXX</em> constants. </p> <p class="para"> <strong><code>SOAP_PERSISTENCE_REQUEST</code></strong> - SoapServer data does not persist between requests. This is the <em class="emphasis">default</em> behavior of any SoapServer object after setClass is called. </p> <p class="para"> <strong><code>SOAP_PERSISTENCE_SESSION</code></strong> - SoapServer data persists between requests. This is accomplished by serializing the SoapServer class data into <var class="varname"><var class="varname"><a href="reserved.variables.session.html" class="classname">$_SESSION['_bogus_session_name']</a></var></var>, because of this <span class="function"><a href="function.session-start.html" class="function">session_start()</a></span> must be called before this persistence mode is set. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-soapserver.setpersistence-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> No value is returned. </p> </div> <div class="refsect1 examples" id="refsect1-soapserver.setpersistence-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-5327"> <p><strong>Example #1 <span class="function"><strong>SoapServer::setPersistence()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /> </span><span style="color: #007700">class </span><span style="color: #0000BB">MyFirstPersistentSoapServer </span><span style="color: #007700">{<br /> private </span><span style="color: #0000BB">$resource</span><span style="color: #007700">; </span><span style="color: #FF8000">// (Such as PDO, mysqli, etc..)<br /> </span><span style="color: #007700">public </span><span style="color: #0000BB">$myvar1</span><span style="color: #007700">;<br /> public </span><span style="color: #0000BB">$myvar2</span><span style="color: #007700">;<br /><br /> public function </span><span style="color: #0000BB">__construct</span><span style="color: #007700">() {<br /> </span><span style="color: #0000BB">$this</span><span style="color: #007700">-></span><span style="color: #0000BB">__wakeup</span><span style="color: #007700">(); </span><span style="color: #FF8000">// We're calling our wakeup to handle starting our resource<br /> </span><span style="color: #007700">}<br /><br /> public function </span><span style="color: #0000BB">__wakeup</span><span style="color: #007700">() {<br /> </span><span style="color: #0000BB">$this</span><span style="color: #007700">-></span><span style="color: #0000BB">resource </span><span style="color: #007700">= </span><span style="color: #0000BB">CodeToStartOurResourceUp</span><span style="color: #007700">();<br /> }<br /><br /> public function </span><span style="color: #0000BB">__sleep</span><span style="color: #007700">() {<br /> </span><span style="color: #FF8000">// We make sure to leave out $resource here, so our session data remains persistent<br /> // Failure to do so will result in the failure during the unserialization of data<br /> // on the next request; thus, our SoapObject would not be persistent across requests.<br /> </span><span style="color: #007700">return array(</span><span style="color: #DD0000">'myvar1'</span><span style="color: #007700">,</span><span style="color: #DD0000">'myvar2'</span><span style="color: #007700">);<br /> }<br /> }<br /><br /> try {<br /> </span><span style="color: #0000BB">session_start</span><span style="color: #007700">();<br /> </span><span style="color: #0000BB">$server </span><span style="color: #007700">= new </span><span style="color: #0000BB">SoapServer</span><span style="color: #007700">(</span><span style="color: #0000BB">null</span><span style="color: #007700">, array(</span><span style="color: #DD0000">'uri' </span><span style="color: #007700">=> </span><span style="color: #0000BB">$_SERVER</span><span style="color: #007700">[</span><span style="color: #DD0000">'REQUEST_URI'</span><span style="color: #007700">]));<br /> </span><span style="color: #0000BB">$server</span><span style="color: #007700">-></span><span style="color: #0000BB">setClass</span><span style="color: #007700">(</span><span style="color: #DD0000">'MyFirstPersistentSoapServer'</span><span style="color: #007700">);<br /> </span><span style="color: #FF8000">// setPersistence MUST be called after setClass, because setClass's<br /> // behavior sets SESSION_PERSISTENCE_REQUEST upon enacting the method.<br /> </span><span style="color: #0000BB">$server</span><span style="color: #007700">-></span><span style="color: #0000BB">setPersistence</span><span style="color: #007700">(</span><span style="color: #0000BB">SOAP_PERSISTENCE_SESSION</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$server</span><span style="color: #007700">-></span><span style="color: #0000BB">handle</span><span style="color: #007700">();<br /> } catch(</span><span style="color: #0000BB">SoapFault $e</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">error_log</span><span style="color: #007700">(</span><span style="color: #DD0000">"SOAP ERROR: "</span><span style="color: #007700">. </span><span style="color: #0000BB">$e</span><span style="color: #007700">-></span><span style="color: #0000BB">getMessage</span><span style="color: #007700">());<br /> }<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-soapserver.setpersistence-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="methodname"><a href="soapserver.setclass.html" class="methodname" rel="rdfs-seeAlso">SoapServer::setClass()</a> - Sets the class which handles SOAP requests</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="soapserver.setobject.html">SoapServer::setObject</a></div> <div class="next" style="text-align: right; float: right;"><a href="soapserver.soapserver.html">SoapServer::SoapServer</a></div> <div class="up"><a href="class.soapserver.html">SoapServer</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>