I am trying to implement Fire and Forget in PHP, and I use this code (found here):
$parts = parse_url($url);
try {
$socket = $this->openSocket($parts['host'], ($parts['port'] ?? $parts['scheme'] === 'https' ? 443 : 80));
} catch (Exception $e) {
$socket = null;
}
if (!$socket) {
return false;
}
$jsPostData = json_encode($postData, JSON_THROW_ON_ERROR);
$contentLength = strlen($jsPostData);
$request = "POST {$parts['path']} HTTP/1.1rn";
$request .= "Host: {$parts['host']}rn";
$request .= "Authorization: Bearer " . $bearerToken . "rn";
$request .= "Content-Length: {$contentLength}rn";
$request .= "Content-Type: application/jsonrnrn";
$request .= $jsPostData;
fwrite($socket, $request);
fclose($socket);
It results with a request like this:
POST /my_path HTTP/1.1
Host: my_url
Authorization: Bearer my_bearer_token
Content-Length: 263
Content-Type: application/json
{"event":"...."}
I get the error:
HTTP/1.1 400 Bad Request
Server: awselb/2.0
Date: Fri, 06 Oct 2023 09:43:17 GMT
Content-Type: text/html
Content-Length: 220
I do not know if its a really bad request or its a permissions fail.