craftcms / element-api

Create a JSON API/Feed for your elements in Craft.
MIT License
498 stars 56 forks source link

Uncaught yii\web\HeadersAlreadySentException #138

Closed diluno closed 3 years ago

diluno commented 3 years ago

Description

I've got a pretty large endpoint, and every fifth time or so I get the following error: <b>Fatal error</b>: Uncaught yii\web\HeadersAlreadySentException: Headers already sent in /home/forge/**.**.**/vendor/yiisoft/yii2/web/Response.php on line 437. in /home/forge/**.**.**/vendor/yiisoft/yii2/web/Response.php:373

The error is displayed after the whole json output.

Because the frontend is on a different domain than the Craft instance, I set the following headers in element-api.php: Craft::$app->getResponse()->getHeaders()->set('Access-Control-Allow-Origin', '*');

Additional info

diluno commented 3 years ago

Nevermind, I was running PHP 7.3 – seems to be working with 7.4 🤦‍♂️