简体   繁体   中英

PHP - How is it possible to succesfully POST a large JSON object with one cURL POST request?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM