EventSource icon indicating copy to clipboard operation
EventSource copied to clipboard

EventSource's response has a MIME type issue

Open surjit opened this issue 10 years ago • 3 comments

EventSource's response has a MIME type ("text/html") that is not "text/event-stream". Aborting the connection. client.html:1

Fatal error: Uncaught exception 'Predis\Connection\ConnectionException' with message 'No connection could be made because the target machine actively refused it. [tcp://127.0.0.1:6379]' in vendor\predis\predis\src\Connection\AbstractConnection.php:146 Stack trace: #0 \vendor\predis\predis\src\Connection\StreamConnection.php(85): Predis\Connection\AbstractConnection->onConnectionError('No connection c...', 10061) #1 \vendor\predis\predis\src\Connection\StreamConnection.php(56): Predis\Connection\StreamConnection->tcpStreamInitializer(Object(Predis\Connection\Parameters)) #2 \vendor\predis\predis\src\Connection\AbstractConnection.php(95): Predis\Connection\StreamConnection->createResource() #3 \vendor\predis\predis\src\Connection\StreamConnection.php(142): Predis\Connection\AbstractConnection->connect() #4 in \vendor\predis\predis\src\Connection\AbstractConnection.php on line 146

surjit avatar Jul 28 '15 11:07 surjit

It's solved, thanks,

surjit avatar Jul 28 '15 11:07 surjit

How did you solve it?

ps92 avatar Jul 18 '16 20:07 ps92

/*

  • This file is part of EventSource.
  • (c) Igor Wiedler [email protected]
  • For the full copyright and license information, please view the LICENSE
  • file that was distributed with this source code. */

namespace Igorw\EventSource;

/**

  • Generates a stream in the W3C EventSource format

  • http://dev.w3.org/html5/eventsource/ */ class Stream { private $buffer; private $handler;

    public function __construct($handler = null) { $this->buffer = new \SplQueue(); $this->buffer->setIteratorMode(\SplQueue::IT_MODE_DELETE); $this->handler = $handler ?: new EchoHandler(); }

    public function event() { $event = new Event(); $this->buffer->enqueue($event);

     $that = $this;
    
     $wrapper = new EventWrapper($event, function () use ($that) {
         return $that;
     });
    
     return $wrapper;
    

    }

    public function flush() { foreach ($this->buffer as $event) { $chunk = $event->dump(); if ('' !== $chunk) { call_user_func($this->handler, $chunk); } } }

    public function getHandler() { return $this->handler; }

    static public function setHeaders($headers = array()){ $headers = array_merge(self::getHeaders(), $headers); foreach ($headers as $name => $value) { header("$name: $value"); } }

    static public function getHeaders() { return array( 'Content-Type' => 'text/event-stream', 'Transfer-Encoding' => 'identity', 'Cache-Control' => 'no-cache', 'X-Accel-Buffering' => 'no', 'Connection' => 'keep-alive', 'Access-Control-Allow-Origin' => '*' ); } }

jiangwu10057 avatar May 09 '18 02:05 jiangwu10057