라이브러리
[PHP] SoapServer::setPersistence - SoapServer 지속성 모드를 설정합니다.
SoapServer::setPersistence
PHP의 SoapServer는 SOAP(Simple Object Access Protocol) 서비스를 제공하는 클래스입니다. SoapServer::setPersistence 메소드는 SoapServer의ERSISTENCE 설정을 변경하는 메소드입니다.
# persistence 옵션
SoapServer::setPersistence 메소드는 두 가지 옵션을 제공합니다.
- `SOAP_PERSISTENCE_SESSION` : 세션 영역에 저장합니다. 세션 영역은 요청당이 영역입니다.
- `SOAP_PERSISTENCE_REQUEST` : 요청당이 영역에 저장합니다. 요청당 영역은 요청당이 영역입니다.
- `SOAP_PERSISTENCE_NONE` : 저장하지 않습니다.
# 예제
#hostingforum.kr
php
<?php
// SoapServer 설정
$server = new SoapServer(null, array(
'uri' => 'http://example.com/soap',
'location' => 'http://example.com/soap',
'soap_version' => SOAP_1_2,
'cache_wsdl' => WSDL_CACHE_NONE,
'classmap' => array('MyService' => 'MyService'),
'persist' => SOAP_PERSISTENCE_SESSION // persistence 옵션
));
// MyService 클래스
class MyService {
private $data;
public function __construct() {
$this->data = array();
}
public function add($name, $age) {
$this->data[] = array('name' => $name, 'age' => $age);
return $this->data;
}
public function getData() {
return $this->data;
}
}
// SoapServer 실행
$server->addFunction('add');
$server->addFunction('getData');
// SoapClient로 요청
$client = new SoapClient('http://example.com/soap?wsdl');
// 요청 1
$result = $client->add('John', 30);
print_r($result);
// 요청 2
$result = $client->add('Jane', 25);
print_r($result);
// 요청 3
$result = $client->getData();
print_r($result);
?>
# 결과
위 예제에서 SoapServer::setPersistence 메소드는 `SOAP_PERSISTENCE_SESSION` 옵션을 사용합니다. 따라서 SoapServer는 세션 영역에 저장됩니다. 요청 1과 요청 2는 동일한 세션 영역에 저장되며, 요청 3는 세션 영역의 데이터를 반환합니다.
#hostingforum.kr
php
Array
(
[0] => Array
(
[name] => John
[age] => 30
)
)
Array
(
[0] => Array
(
[name] => John
[age] => 30
)
[1] => Array
(
[name] => Jane
[age] => 25
)
)
Array
(
[0] => Array
(
[name] => John
[age] => 30
)
[1] => Array
(
[name] => Jane
[age] => 25
)
)
# 결론
SoapServer::setPersistence 메소드는 SoapServer의ERSISTENCE 설정을 변경하는 메소드입니다. persistence 옵션은 세션 영역에 저장, 요청당 영역에 저장, 저장하지 않는 세 가지 옵션을 제공합니다. 위 예제에서 SoapServer::setPersistence 메소드는 `SOAP_PERSISTENCE_SESSION` 옵션을 사용하여 세션 영역에 저장되었습니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.