Skip to content

Commit 8f3da06

Browse files
committed
Catch exceptions in APCU when error handler set
1 parent 34ac23c commit 8f3da06

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/Dispatch.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,32 @@ public function handle(Request $request, $type = self::MASTER_REQUEST, $catch =
129129
{
130130
$dispatchKey = 'dsptch:' . base64_encode($request->getUri());
131131
$success = $response = null;
132-
$hasApc = function_exists('apcu_fetch');
133-
if($hasApc)
132+
if(function_exists('apcu_fetch'))
134133
{
135-
$response = apcu_fetch($dispatchKey, $success);
134+
try
135+
{
136+
$response = apcu_fetch($dispatchKey, $success);
137+
}
138+
catch(\Exception $e)
139+
{
140+
//Catch possible exceptions if the error handler is set to throw
141+
$response = null;
142+
$success = false;
143+
}
136144
}
137145
if(!$success)
138146
{
139147
$response = $this->getResponseForPath($this->getDispatchablePath($request), $request);
140-
if($hasApc && $response->getStatusCode() === 200)
148+
if(function_exists('apcu_add') && $response->getStatusCode() === 200)
141149
{
142-
apcu_add($dispatchKey, $response, 86400);
150+
try
151+
{
152+
apcu_add($dispatchKey, $response, 86400);
153+
}
154+
catch(\Exception $e)
155+
{
156+
//Catch possible exceptions if the error handler is set to throw
157+
}
143158
}
144159
}
145160

0 commit comments

Comments
 (0)