Curl request does not work depending on JSON size

Asked

Viewed 321 times

0

My problem is that depending on the size of the JSON sent, the request CUrl does not work, ie I send 2 photos on JSON, right, but 4 is already reason for a TimeOut.

The problem is not in API for in the Postman works regardless of the size of the JSON, I mean, I think it’s some configuration that I’m not setting, someone has some idea?

Structure of the Curl...

$ch = curl_init();

curl_setopt_array($ch, array(
            CURLOPT_URL => trim($this->vg['url'] . $url1 . $url2),
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => $method,
            CURLOPT_POSTFIELDS => $json,
            CURLOPT_HTTPHEADER => array(
              "Cache-control: no-cache",
              "Accept: application/json",
              "Content-type: application/json",
            ),
          ));

1 answer

1


Curl timeout is at 30s, change the line below:

CURLOPT_TIMEOUT => 30

for (1800 = 30 min):

CURLOPT_TIMEOUT => 1800

Source: http://php.net/manual/en/function.curl-setopt.php

Also put the code below first. Note: 30*60 = 1800s = 30min maximum timeout (maximum runtime). And post_max_size tb has influence on uploading files, according to php documentation.

ini_set('max_execution_time', 30*60);
ini_set('post_max_size','256M');

Source: https://secure.php.net/manual/en/ini.core.php

  • I had already tried that didn’t solve

  • Is your server enabled to reconfigure running by php? What error is displayed?

  • Dude... the Curl timeout is in 30seconds (CURLOPT_TIMEOUT => 30), already tried to increase it also to CURLOPT_TIMEOUT => 1800?

  • Yes kkk, I increased to the maximum, just stays in an infinite looping, I just increase the json a little and it’s gone

  • Strange... I’ve used php Curl to send up to 4GB and it worked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.