-
Notifications
You must be signed in to change notification settings - Fork 319
Open
Description
Bug report
- Vercel CLI Version:
39.0.4
- NodeJS Version:
18.x
- vercel-php:
0.7.3
- URL: https://pln-api.vercel.app
- PHP info: https://pln-api.vercel.app/debug
- Repository:
No
Description
At the beginning of the deployment, using curl had no problems at all. But 1 day later, the API suddenly responded to an error with a message: “Call to undefined function curl_init()”. I tried several solutions in the problem report history of this repository with the same problem, but all of them did not work at all.
I tried the following:
- Changing the NodeJS version to
18.x
,20.x
,22.x
- Changed the version of
vercel-php
invercel.json
with several versions:0.7.3
,0.6.2
- Changed the use of
curl_*
tofile_get_contents
withstream_context_create
customization using the same flow
From all the experiments above, the API now does not provide any response, only a blank page with HTTP 200 status code. Actually this is a simple project to create a RESTFull API by calling the API from another server, then returning the response back to the client. Here are some code on my project:
project-structure
├─ api
│ ├─ debug.php
│ └─ handler.php
├─ index.min.html
├─ openapi.min.json
└─ vercel.json
vercel.json
:
{
"functions": {
"api/**/*.php": {
"runtime": "[email protected]"
}
},
"routes": [
{ "src": "/", "dest": "/index.min.html" },
{ "src": "/oas", "dest": "/api/handler.php" },
{ "src": "/debug", "dest": "/api/debug.php" },
{ "src": "/api/(.*)", "dest": "/api/handler.php" }
]
}
api/debug.php
:
<?php phpinfo();
api/handler.php
:
<?php
// error_reporting(0);
// ...some code
try {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$body = file_get_contents('php://input');
if (
$method === 'GET' &&
!empty($operation['requestBody']) &&
empty($body)
) {
$body = json_encode($_GET);
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_HTTPHEADER, $forwardedHeaders);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$contentType = 'text/plain';
try {
json_decode($response, false, 512, JSON_THROW_ON_ERROR);
$contentType = 'application/json';
} catch (JsonException $e) {
$contentType = 'text/plain';
}
http_response_code($httpCode);
header("Content-Type: $contentType");
echo $response;
} catch (\Throwable $th) {
echo json_encode([
"code" => "500",
"message" => "There is a gateway server error, please try again in a while.",
"data" => $th->getMessage()
]);
}
Metadata
Metadata
Assignees
Labels
No labels