本文整理汇总了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})");
}