0

I'm migrating from Laravel 8 to Laravel 8 + Octane / Swoole. All works fine, but php://input always are empty. Also, I check $_POST and $_SERVER values.

file_get_contents('php://input') is used by AWS SNS Message Validator.

Any alterantive to read php://input?

PHP code

echo "php://input: ".file_get_contents('php://input');

With PHP-FPM

$ curl -i -X POST --data "dataaaa" https://example.com/aws/sns/webhook
php://input: dataaaa

With Octane+Swoole

$ curl -i -X POST --data "dataaaa" https://example.com/aws/sns/webhook
php://input:
pablorsk
  • 3,861
  • 1
  • 32
  • 37
  • `php://input` is built into PHP, those frameworks shouldn't change it. – Barmar Jul 29 '21 at 20:29
  • I think the same as you, but it is always empty using swoole. With PHP-FPM works fine. – pablorsk Jul 29 '21 at 20:50
  • Note that from the CLI SAPI or builtin webserver that `php://input` stream wrapper is not available with `enctype="multipart/form-data"`. See [the manual for details](https://www.php.net/wrappers.php). – Sherif Jul 30 '21 at 02:43

1 Answers1

1

Problem

php://input are not available on Swoole. Always are the same running process.

Solution: PSR-7 Request

use Psr\Http\Message\RequestInterface;

public function sesSubscriptionWebhook(RequestInterface $request)
{
    // $input = file_get_contents('php://input'); // dont work on swoole
    $input = $request->getBody();
}

Of course, with octane, symfony/psr-http-message-bridge and nyholm/psr7 are required for Laravel PSR-7 requests.

Also, if your problem is related with AWS SES, you need to change Message::fromRawPostData() to Message::fromPsrRequest($request).

pablorsk
  • 3,861
  • 1
  • 32
  • 37