Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Fix ShutdownScheduler that could skip deferred events when already in…
Browse files Browse the repository at this point in the history
… deferred loop.
  • Loading branch information
cdujeu committed Jul 4, 2016
1 parent 6f14104 commit 00c4fe6
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions core/src/core/classes/class.AJXP_ShutdownScheduler.php
Expand Up @@ -81,24 +81,33 @@ public function registerShutdownEvent()
$this->callbacks[] = $callback;
return true;
}
public function callRegisteredShutdown()
{
session_write_close();

public function callRegisteredShutdown()
{
session_write_close();
if (!headers_sent()) {
$size = ob_get_length();
header("Connection: close\r\n");
//header("Content-Encoding: none\r\n");
header("Content-Length: $size");
}
$size = ob_get_length();
header("Connection: close\r\n");
//header("Content-Encoding: none\r\n");
header("Content-Length: $size");
}
ob_end_flush();
flush();
foreach ($this->callbacks as $arguments) {
$callback = array_shift($arguments);
try {
call_user_func_array($callback, $arguments);
} catch (Exception $e) {
AJXP_Logger::error(__CLASS__, __FUNCTION__, array("context"=>"Applying hook ".get_class($callback[0])."::".$callback[1], "message" => $e->getMessage()));
}
}
}
flush();
$index = 0;
while (count($this->callbacks)) {
$arguments = array_shift($this->callbacks);
$callback = array_shift($arguments);
try {
call_user_func_array($callback, $arguments);
} catch (\Exception $e) {
AJXP_Logger::error(__CLASS__, __FUNCTION__, array("context" => "Applying hook " . get_class($callback[0]) . "::" . $callback[1], "message" => $e->getMessage()));
}
$index++;
if($index > 200) {
AJXP_Logger::error(__CLASS__, __FUNCTION__, "Breaking ShutdownScheduler loop, seems too big (200)");
break;
}
}
}

}

0 comments on commit 00c4fe6

Please sign in to comment.