Skip to content

Commit bb25e42

Browse files
scottlucas1ma
authored andcommitted
Fix hang when max_execution_time is zero
1 parent d5634f5 commit bb25e42

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/RedisSessionHandler.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,13 @@ public function gc($maxlifetime)
199199
private function acquireLockOn($session_id)
200200
{
201201
$wait = self::MIN_WAIT_TIME;
202+
if ($this->lock_ttl) {
203+
$options = ['nx', 'ex' => $this->lock_ttl];
204+
} else {
205+
$options = ['nx'];
206+
}
202207

203-
while (false === $this->redis->set("{$session_id}_lock", '', ['nx', 'ex' => $this->lock_ttl])) {
208+
while (false === $this->redis->set("{$session_id}_lock", '', $options)) {
204209
usleep($wait);
205210

206211
if (self::MAX_WAIT_TIME > $wait) {

tests/e2e/BasicTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,20 @@ public function testFlushedDatabase()
137137
$this->assertSame(1, $this->redis->dbSize());
138138
}
139139

140+
/**
141+
* This test checks that the server behaves correctly when a script is run that has no time limit
142+
*/
143+
public function testUnlimitedExecutionTime()
144+
{
145+
$response = $this->http->send(
146+
new Request('GET', '/visit-counter.php?with_no_time_limit')
147+
);
148+
149+
$this->assertSame('1', (string) $response->getBody());
150+
$this->assertCreatedNewSession($response);
151+
$this->assertSame(1, $this->redis->dbSize());
152+
}
153+
140154
/**
141155
* Asserts whether a received request triggered the creation of a new session.
142156
* It does so by searching for and inspecting the 'Set-Cookie' header.

tests/webroot/visit-counter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
require_once __DIR__.'/../../vendor/autoload.php';
88

9+
if (isset($_GET['with_no_time_limit'])) {
10+
set_time_limit(0);
11+
}
12+
913
session_set_save_handler(new \UMA\RedisSessionHandler(), true);
1014

1115
session_start();

0 commit comments

Comments
 (0)