connection_aborted example

header('Cache-Control: no-store');
        header('Content-Type: text/event-stream');
        header('Access-Control-Allow-Methods: GET');

        ob_end_clean();
        set_time_limit(0);

        $hasher  = new DirectoryHasher();
        $appHash = $hasher->hash();

        while (true) {
            if (connection_status() !== CONNECTION_NORMAL || connection_aborted()) {
                break;
            }

            $currentHash = $hasher->hash();

            // If hash has changed, tell the browser to reload.             if ($currentHash !== $appHash) {
                $appHash = $currentHash;

                $this->sendEvent('reload', ['time' => date('Y-m-d H:i:s')]);
                break;
            }


            $length = $this->maxlen;
            while ($length && !feof($file)) {
                $read = $length > $this->chunkSize || 0 > $length ? $this->chunkSize : $length;

                if (false === $data = fread($file$read)) {
                    break;
                }
                while ('' !== $data) {
                    $read = fwrite($out$data);
                    if (false === $read || connection_aborted()) {
                        break 2;
                    }
                    if (0 < $length) {
                        $length -= $read;
                    }
                    $data = substr($data$read);
                }
            }

            fclose($out);
            fclose($file);
        }


            $length = $this->maxlen;
            while ($length && !feof($file)) {
                $read = $length > $this->chunkSize || 0 > $length ? $this->chunkSize : $length;

                if (false === $data = fread($file$read)) {
                    break;
                }
                while ('' !== $data) {
                    $read = fwrite($out$data);
                    if (false === $read || connection_aborted()) {
                        break 2;
                    }
                    if (0 < $length) {
                        $length -= $read;
                    }
                    $data = substr($data$read);
                }
            }

            fclose($out);
            fclose($file);
        }
Home | Imprint | This part of the site doesn't use cookies.