本文整理匯總了PHP中Zend_Session::setExpirationSeconds方法的典型用法代碼示例。如果您正苦於以下問題:PHP Zend_Session::setExpirationSeconds方法的具體用法?PHP Zend_Session::setExpirationSeconds怎麽用?PHP Zend_Session::setExpirationSeconds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend_Session
的用法示例。
在下文中一共展示了Zend_Session::setExpirationSeconds方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testSetExpirationSeconds
/**
* test expiration of namespaces and namespace variables by seconds
* expect expiration of specified keys/namespace
*/
public function testSetExpirationSeconds()
{
$s = new Zend_Session('expireAll');
$s->a = 'apple';
$s->p = 'pear';
$s->o = 'orange';
$s->setExpirationSeconds(5);
$core = Zend_Session_Core::getInstance();
$core->regenerateId();
$id = Zend_Session_Core::getId();
session_write_close();
// release session so process below can use it
sleep(4);
// not long enough for things to expire
exec($this->script . "expireAll {$id} expireAll", $result);
$result = $this->sortResult($result);
$expect = ';a === apple;o === orange;p === pear';
$this->assertTrue($result === $expect, "iteration over default Zend_Session namespace failed; expecting result === '{$expect}', but got '{$result}'");
sleep(2);
// long enough for things to expire (total of 6 seconds waiting, but expires in 5)
exec($this->script . "expireAll {$id} expireAll", $result);
$result = array_pop($result);
$this->assertTrue($result === '', "iteration over default Zend_Session namespace failed; expecting result === '', but got '{$result}')");
session_start();
// resume artificially suspended session
// We could split this into a separate test, but actually, if anything leftover from above
// contaminates the tests below, that is also a bug that we want to know about.
$s = new Zend_Session('expireGuava');
$s->setExpirationSeconds(5, 'g');
// now try to expire only 1 of the keys in the namespace
$s->g = 'guava';
$s->p = 'peach';
$s->p = 'plum';
session_write_close();
// release session so process below can use it
sleep(6);
// not long enough for things to expire
exec($this->script . "expireAll {$id} expireGuava", $result);
$result = $this->sortResult($result);
session_start();
// resume artificially suspended session
$this->assertTrue($result === ';p === plum', "iteration over named Zend_Session namespace failed (result={$result})");
}