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:
18
sse.php
18
sse.php
@@ -197,19 +197,22 @@ 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);
|
||||
$lines = rtrim ($lines);
|
||||
// As data may contains multiple lines, split them
|
||||
foreach (explode ("\n", $lines) as $line)
|
||||
{
|
||||
if (key_exists ($event, $this->handlers) &&
|
||||
is_callable ($this->handlers[$event]))
|
||||
{
|
||||
$array = array ($data);
|
||||
$array = array ($line);
|
||||
if (key_exists ($event, $this->handlersParams))
|
||||
$array = array_merge ($array, $this->handlersParams[$event]);
|
||||
$data = call_user_func_array ($this->handlers[$event], $array);
|
||||
$line = call_user_func_array ($this->handlers[$event], $array);
|
||||
}
|
||||
if ($data === false)
|
||||
if ($line === false)
|
||||
continue;
|
||||
// If the event is data, do not display "event:data", but data:
|
||||
// immediately
|
||||
@@ -218,9 +221,10 @@ class sse
|
||||
echo "event: $event\n";
|
||||
$event = "data";
|
||||
}
|
||||
echo "$event: ".implode ("\n$event: ", explode ("\n", rtrim ($data))).
|
||||
echo "$event: ".implode ("\n$event: ", explode ("\n", rtrim ($line))).
|
||||
"\n\n";
|
||||
}
|
||||
}
|
||||
if (defined ("PHPUNIT"))
|
||||
{
|
||||
$testloop--;
|
||||
|
||||
Reference in New Issue
Block a user