Supported Versions: PHP 4 >= 4.0.2, PHP 5, PHP 7, PHP 8
Set an option for a cURL transfer
<?php curl_setopt(CurlHandle $handle, int $option, mixed $value): bool
<?php {
if ($this->curlHandleNext === null) {
$this->curlHandleNext = curl_init("http://{$this->apiUrl}/2018-06-01/runtime/invocation/next");
curl_setopt($this->curlHandleNext, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($this->curlHandleNext, CURLOPT_FAILONERROR, true);
$phpVersion = substr(PHP_VERSION, 0, strpos(PHP_VERSION, '.', 2));
<?php if ($this->curlHandleNext === null) {
$this->curlHandleNext = curl_init("http://{$this->apiUrl}/2018-06-01/runtime/invocation/next");
curl_setopt($this->curlHandleNext, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($this->curlHandleNext, CURLOPT_FAILONERROR, true);
$phpVersion = substr(PHP_VERSION, 0, strpos(PHP_VERSION, '.', 2));
curl_setopt($this->curlHandleNext, CURLOPT_USERAGENT, "bref/{$this->layer}/$phpVersion");
<?php curl_setopt($this->curlHandleNext, CURLOPT_FAILONERROR, true);
$phpVersion = substr(PHP_VERSION, 0, strpos(PHP_VERSION, '.', 2));
curl_setopt($this->curlHandleNext, CURLOPT_USERAGENT, "bref/{$this->layer}/$phpVersion");
}
<?php $contextBuilder = new ContextBuilder;
curl_setopt($this->curlHandleNext, CURLOPT_HEADERFUNCTION, function ($ch, $header) use ($contextBuilder) {
if (! preg_match('/:\s*/', $header)) {
return strlen($header);
}
[$name, $value] = preg_split('/:\s*/', $header, 2);
$name = strtolower($name);
$value = trim($value);
if ($name === 'lambda-runtime-aws-request-id') {
$contextBuilder->setAwsRequestId($value);
}
if ($name === 'lambda-runtime-deadline-ms') {
$contextBuilder->setDeadlineMs(intval($value));
}
if ($name === 'lambda-runtime-invoked-function-arn') {
$contextBuilder->setInvokedFunctionArn($value);
}
if ($name === 'lambda-runtime-trace-id') {
$contextBuilder->setTraceId($value);
}
return strlen($header);
});
$body = '';
<?php $body = '';
curl_setopt($this->curlHandleNext, CURLOPT_WRITEFUNCTION, function ($ch, $chunk) use (&$body) {
$body .= $chunk;
return strlen($chunk);
});
curl_exec($this->curlHandleNext);
if (curl_errno($this->curlHandleNext) > 0) {
<?php if ($this->curlHandleResult === null) {
$this->curlHandleResult = curl_init();
curl_setopt($this->curlHandleResult, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($this->curlHandleResult, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->curlHandleResult, CURLOPT_FAILONERROR, true);
}
<?php if ($this->curlHandleResult === null) {
$this->curlHandleResult = curl_init();
curl_setopt($this->curlHandleResult, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($this->curlHandleResult, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->curlHandleResult, CURLOPT_FAILONERROR, true);
}
<?php $this->curlHandleResult = curl_init();
curl_setopt($this->curlHandleResult, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($this->curlHandleResult, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->curlHandleResult, CURLOPT_FAILONERROR, true);
}
curl_setopt($this->curlHandleResult, CURLOPT_URL, $url);
<?php curl_setopt($this->curlHandleResult, CURLOPT_FAILONERROR, true);
}
curl_setopt($this->curlHandleResult, CURLOPT_URL, $url);
curl_setopt($this->curlHandleResult, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($this->curlHandleResult, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
<?php }
curl_setopt($this->curlHandleResult, CURLOPT_URL, $url);
curl_setopt($this->curlHandleResult, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($this->curlHandleResult, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Content-Length: ' . strlen($jsonData),
<?php curl_setopt($this->curlHandleResult, CURLOPT_URL, $url);
curl_setopt($this->curlHandleResult, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($this->curlHandleResult, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Content-Length: ' . strlen($jsonData),
]);
curl_exec($this->curlHandleResult);
if (curl_errno($this->curlHandleResult) > 0) {
$errorMessage = curl_error($this->curlHandleResult);