Skip to content

Problem with curl for PHP runtime #584

Open

Description

@decryptable

Bug report

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:

  1. Changing the NodeJS version to 18.x, 20.x, 22.x
  2. Changed the version of vercel-php in vercel.json with several versions: 0.7.3, 0.6.2
  3. Changed the use of curl_* to file_get_contents with stream_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:

Image

project-structure
├─ api
│  ├─ debug.php
│  └─ handler.php
├─ index.min.html
├─ openapi.min.json
└─ vercel.json

vercel.json :

{
  "functions": {
    "api/**/*.php": {
      "runtime": "vercel-php@0.6.2"
    }
  },
  "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()
    ]);
}

Activity

  1. f3l1x commented on Jun 9, 2025

    @f3l1x
    Collaborator

    Hi, thank you for report, I will take a look.

  2. qkqpttgf commented on Jul 10, 2025

    @qkqpttgf

    same.
    a blank page with HTTP 200 status code.

  3. nadar commented on Jul 16, 2025

    @nadar

    i would say its a duplication of #582

  4. f3l1x commented on Jul 18, 2025

    @f3l1x
    Collaborator

    Hi @decryptable and others. Please take a look at #582 (comment)

  5. qkqpttgf commented on Jul 28, 2025

    @qkqpttgf

    @f3l1x I am sorry, but, 18/20/22 all blank page now.

  6. f3l1x commented on Jul 28, 2025

    @f3l1x
    Collaborator

    What do you mean? I have deployed many services and examples and they are OK. I need more info.

  7. decryptable commented on Jul 28, 2025

    @decryptable
    Author

    @f3l1x sorry for the late reply. after doing some experiments, I have another conclusion to the problem I am facing.

    the third-party API server seems to reject API calls from certain country IPs, and only allow IP requests from servers with certain country providers.

    In my case, this might be the main problem. Because after I tried to create an API server with another programming language with the same flow —like in the previous PHP code, this problem still occurred.

    In conclusion, the API server that I called in fact always refused to provide a response if it was called from an IP that was not from a certain country.

    Can I close this issue?

  8. qkqpttgf commented on Jul 29, 2025

    @qkqpttgf

    What do you mean? I have deployed many services and examples and they are OK. I need more info.

    my project url:
    https://github.com/qkqpttgf/OneManager-php ,
    deploy to vercel use:
    https://scfonedrive.github.io/Vercel/Deploy.html , they works well for years.
    but now, it is a blank page after deploy, nothing changed .

  9. f3l1x commented on Jul 29, 2025

    @f3l1x
    Collaborator

    @qkqpttgf This https://scfonedrive.github.io/Vercel/Deploy.html is some custom deployment? Do you have any vercel.json example for https://github.com/qkqpttgf/OneManager-php?

  10. qkqpttgf commented on Aug 1, 2025

    @qkqpttgf

    @qkqpttgf This https://scfonedrive.github.io/Vercel/Deploy.html is some custom deployment? Do you have any vercel.json example for https://github.com/qkqpttgf/OneManager-php?

    sorry, out for work 2 days.

    these 2 page written by me, and vercel.json is line 410 and 701 in Deploy.html,
    after deploy, in vercel it like this:

    Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions