sse : if there is multiples lines in the log, manage them without loose

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@6086 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2020-09-07 10:04:26 +00:00
parent 0dcba9466d
commit 88fa996069

44
sse.php
View File

@@ -197,29 +197,33 @@ class sse
// Try to get data from backends
foreach ($this->files as $event => $filePath)
{
$data = $this->backendGet ($event);
if ($data === false)
$lines = $this->backendGet ($event);
if ($lines === false)
continue;
$data = rtrim ($data);
if (key_exists ($event, $this->handlers) &&
is_callable ($this->handlers[$event]))
$lines = rtrim ($lines);
// As data may contains multiple lines, split them
foreach (explode ("\n", $lines) as $line)
{
$array = array ($data);
if (key_exists ($event, $this->handlersParams))
$array = array_merge ($array, $this->handlersParams[$event]);
$data = call_user_func_array ($this->handlers[$event], $array);
if (key_exists ($event, $this->handlers) &&
is_callable ($this->handlers[$event]))
{
$array = array ($line);
if (key_exists ($event, $this->handlersParams))
$array = array_merge ($array, $this->handlersParams[$event]);
$line = call_user_func_array ($this->handlers[$event], $array);
}
if ($line === false)
continue;
// If the event is data, do not display "event:data", but data:
// immediately
if ($event !== "data")
{
echo "event: $event\n";
$event = "data";
}
echo "$event: ".implode ("\n$event: ", explode ("\n", rtrim ($line))).
"\n\n";
}
if ($data === false)
continue;
// If the event is data, do not display "event:data", but data:
// immediately
if ($event !== "data")
{
echo "event: $event\n";
$event = "data";
}
echo "$event: ".implode ("\n$event: ", explode ("\n", rtrim ($data))).
"\n\n";
}
if (defined ("PHPUNIT"))
{