PHP 8.3.31
Preview: EventStreamResponse.php Size: 2.88 KB
//proc/thread-self/root/home/getspomw/itechservicellc.com/vendor/symfony/http-foundation/EventStreamResponse.php

<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\HttpFoundation;

/**
 * Represents a streaming HTTP response for sending server events
 * as part of the Server-Sent Events (SSE) streaming technique.
 *
 * To broadcast events to multiple users at once, for long-running
 * connections and for high-traffic websites, prefer using the Mercure
 * Symfony Component, which relies on Software designed for these use
 * cases: https://symfony.com/doc/current/mercure.html
 *
 * @see ServerEvent
 *
 * @author Yonel Ceruto <open@yceruto.dev>
 *
 * Example usage:
 *
 *     return new EventStreamResponse(function () {
 *         yield new ServerEvent(time());
 *
 *         sleep(1);
 *
 *         yield new ServerEvent(time());
 *     });
 */
class EventStreamResponse extends StreamedResponse
{
    /**
     * @param int|null $retry The number of milliseconds the client should wait
     *                        before reconnecting in case of network failure
     */
    public function __construct(?callable $callback = null, int $status = 200, array $headers = [], private ?int $retry = null)
    {
        $headers += [
            'Connection' => 'keep-alive',
            'Content-Type' => 'text/event-stream',
            'Cache-Control' => 'private, no-cache, no-store, must-revalidate, max-age=0',
            'X-Accel-Buffering' => 'no',
            'Pragma' => 'no-cache',
            'Expire' => '0',
        ];

        parent::__construct($callback, $status, $headers);
    }

    public function setCallback(callable $callback): static
    {
        if ($this->callback) {
            return parent::setCallback($callback);
        }

        $this->callback = function () use ($callback) {
            if (is_iterable($events = $callback($this))) {
                foreach ($events as $event) {
                    $this->sendEvent($event);

                    if (connection_aborted()) {
                        break;
                    }
                }
            }
        };

        return $this;
    }

    /**
     * Sends a server event to the client.
     *
     * @return $this
     */
    public function sendEvent(ServerEvent $event): static
    {
        if ($this->retry > 0 && !$event->getRetry()) {
            $event->setRetry($this->retry);
        }

        foreach ($event as $part) {
            echo $part;

            if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
                static::closeOutputBuffers(0, true);
                flush();
            }
        }

        return $this;
    }

    public function getRetry(): ?int
    {
        return $this->retry;
    }

    public function setRetry(int $retry): void
    {
        $this->retry = $retry;
    }
}

Directory Contents

Dirs: 6 × Files: 29

Name Size Perms Modified Actions
Exception DIR
- drwxr-xr-x 2025-11-18 19:24:10
Edit Download
File DIR
- drwxr-xr-x 2025-11-18 19:24:10
Edit Download
- drwxr-xr-x 2025-11-18 19:24:10
Edit Download
- drwxr-xr-x 2025-11-18 19:24:10
Edit Download
Session DIR
- drwxr-xr-x 2025-11-18 19:24:12
Edit Download
Test DIR
- drwxr-xr-x 2025-11-18 19:24:12
Edit Download
3.36 KB lrw-r--r-- 2025-10-28 20:23:36
Edit Download
3.16 KB lrw-r--r-- 2025-10-28 20:23:36
Edit Download
13.22 KB lrw-r--r-- 2025-10-28 20:23:36
Edit Download
873 B lrw-r--r-- 2025-10-28 20:23:36
Edit Download
21.22 KB lrw-r--r-- 2025-10-28 20:23:36
Edit Download
1.34 KB lrw-r--r-- 2025-10-28 20:23:36
Edit Download
11.53 KB lrw-r--r-- 2025-10-28 20:23:36
Edit Download
2.88 KB lrw-r--r-- 2025-10-28 20:23:36
Edit Download
3.77 KB lrw-r--r-- 2025-10-28 20:23:36
Edit Download
6.94 KB lrw-r--r-- 2025-10-28 20:23:36
Edit Download
9.07 KB lrw-r--r-- 2025-10-28 20:23:36
Edit Download
5.13 KB lrw-r--r-- 2025-10-28 20:23:36
Edit Download
8.99 KB lrw-r--r-- 2025-10-28 20:23:36
Edit Download
6.45 KB lrw-r--r-- 2025-10-28 20:23:36
Edit Download
1.04 KB lrw-r--r-- 2025-10-28 20:23:36
Edit Download
7.72 KB lrw-r--r-- 2025-10-28 20:23:36
Edit Download
526 B lrw-r--r-- 2025-10-28 20:23:36
Edit Download
2.57 KB lrw-r--r-- 2025-10-28 20:23:36
Edit Download
69.33 KB lrw-r--r-- 2025-10-28 20:23:36
Edit Download
621 B lrw-r--r-- 2025-10-28 20:23:36
Edit Download
3.05 KB lrw-r--r-- 2025-10-28 20:23:36
Edit Download
39.09 KB lrw-r--r-- 2025-10-28 20:23:36
Edit Download
7.75 KB lrw-r--r-- 2025-10-28 20:23:36
Edit Download
3.92 KB lrw-r--r-- 2025-10-28 20:23:36
Edit Download
3.34 KB lrw-r--r-- 2025-10-28 20:23:36
Edit Download
5.64 KB lrw-r--r-- 2025-10-28 20:23:36
Edit Download
3.57 KB lrw-r--r-- 2025-10-28 20:23:36
Edit Download
7.58 KB lrw-r--r-- 2025-10-28 20:23:36
Edit Download
3.05 KB lrw-r--r-- 2025-10-28 20:23:36
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).