Skip to content

Fatal error on stream example #69

Description

@dereuromark

The exact example of the stream output results in

Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 266338320 bytes) in /shared/httpd/app/vendor/jsvrcek/ics/src/CalendarStream.php on line 79

$calendar->setEventsProvider(function () use ($events) {

    $calendarEvents = [];

    foreach ($events as $event) {
        $calendarEvent = new CalendarEvent();
        $calendarEvent->setStart(new \DateTime($event->beginning->toIso8601String()))
            ->setAllDay($event->date_only)
            ->setSummary($event->title)
            ->setDescription($event->description)
            ->setStatus($event->status_string)
            ->setUid($event->id);

        if ($event->end) {
            $calendarEvent->setEnd(new \DateTime($event->end->toIso8601String()));
        }
        if ($event->url) {
            $calendarEvent->setUrl($event->url);
        }
        if ($event->lat && $event->lng) {
            $geo = new Geo();
            $geo->setLatitude($event->lat);
            $geo->setLongitude($event->lng);
            $calendarEvent->setGeo($geo);
        }

        if ($event->location) {
            $location = new \Jsvrcek\ICS\Model\Description\Location();
            $location->setName($event->location);
            $calendarEvent->addLocation($location);
        }

        $image = $event->image(true);
        if ($image) {
            $calendarEvent->setImage([
                'VALUE' => 'URL',
                'URI' => $image,
            ]);
        }

        $calendarEvents[] = $calendarEvent;
    }

    return $calendarEvents;
});

//setup exporter
$calendarExport = new CalendarExport(new CalendarStream, new Formatter());
$calendarExport->addCalendar($calendar);

//set exporter to send items directly to output instead of storing in memory
$calendarExport->getStreamObject()->setDoImmediateOutput(true);

//output .ics formatted text
echo $calendarExport->getStream();

Even commenting out the $calendarExport->getStreamObject()->setDoImmediateOutput(true); part does not help.

PHP 8.2

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions