1

I have wrote a PHP script which receives a Webhook, then processes it's data, creates an array, turns the array to JSON object and finally makes a cURL POST request.

So far it was working perfectly until I had to POST a large JSON. Then it made the POST twice and logged a php-slow for "curl_exec()" line.

I really need to POST each JSON object once, so are there any ideas of how can I fix this and prevent this from happening?

Pinke Helga
  • 6,378
  • 2
  • 22
  • 42
Vicky Fi
  • 79
  • 9
  • 3
    You can start by showing us your code. Then you can give us a more detailed explanation. Please specify how "large" we're talking. While you're at it, take a look at these links: [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) and [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask) – M. Eriksson Mar 16 '19 at 14:46
  • 1
    ... i.e. the **exact** error log – Pinke Helga Mar 16 '19 at 14:48
  • Possible duplicate of [How to POST a large amount of data within PHP curl without memory overhead?](https://stackoverflow.com/questions/32627346/how-to-post-a-large-amount-of-data-within-php-curl-without-memory-overhead) – Pinke Helga Mar 16 '19 at 15:33
  • also duplicate of [How can I send large data over cURL?](https://stackoverflow.com/questions/39644377/how-can-i-sending-large-data-over-curl) – Pinke Helga Mar 16 '19 at 15:39

1 Answers1

-1

If you are working with large a large json, a good practice would be cleaning it and gziping it before sending over http.

//Remove any white spaces and new lines
$no_spaces_json = preg_replace('/(\s|\n)/s', '', $json);
//Gzip it
$gzipped = gzencode($no_spaces_json);

and then send the gzipped string.

Eduardo Junior
  • 362
  • 1
  • 10