0

i am working on route api. In this api, i need to pass huge geocode data in my POST polyline parameter(nearly 1 mb in size).For testing purpose, we added "hello world" in our response file and nothing else.i am getting 3.1 sec as response time.This is due to polyline parameter which is taking 3 sec to send its value(nearly 1 mb in size). I even added gzip then also response taking same time(3 sec). Please help me to optimize curl so that i can get response in milliseconds.

$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_URL, "http://example.com/");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array("polyline"=>"37.779381,-122.418435,37.779381,-122.418435,37.779153,-122.418391...."));
curl_setopt($ch, CURLOPT_ENCODING, "gzip,deflate");
$curl_exec =  curl_exec($ch);
  • Does it have to be realtime? Otherwise you could queue it and process it. – Robinvb Aug 11 '21 at 07:53
  • Your polyline might be too long/complicated. Can't you simplify it? – KIKO Software Aug 11 '21 at 08:14
  • It must be in realtime – muzaffar Aug 11 '21 at 08:14
  • There is no way to simplify polyline as response will show wrong result. – muzaffar Aug 11 '21 at 08:16
  • Hmm.. you could try to do a benchmark when posting a file instead of the raw data and see if that makes a difference? :o – Robinvb Aug 11 '21 at 08:18
  • 1
    OK, it has to be real time, and you have to send 1 MB of data, and you want to do this in milliseconds. I think you need to invest in a faster internet connection and faster server. – KIKO Software Aug 11 '21 at 08:24
  • 1
    One, last thought: Perhaps it takes the server, to which you post this data, a relatively long to process the information and give a response? – KIKO Software Aug 11 '21 at 08:26
  • @KIKOSoftware I think he does not process it yet, and just returns a Hello World. Maybe could try and see what the server response is by just doing a GET request? – Robinvb Aug 11 '21 at 08:31
  • yes. for testing purpose we are printing only "hello world" string in response.GET request is taking response time in milliseconds – muzaffar Aug 11 '21 at 08:39
  • 1
    A GET request is possibly so quick, even if your try to send 1 MB, because of the [Maximum length of HTTP GET request](https://stackoverflow.com/questions/2659952/maximum-length-of-http-get-request), which is something like 8 KB. – KIKO Software Aug 11 '21 at 08:56
  • Yes.GET request is having restriction with data size – muzaffar Aug 11 '21 at 09:23
  • Are both applications in your control? Otherwise you could store it in a file, and post a reference to the file to your API? Besides that I'm not sure if you speed it up much with code – Robinvb Aug 12 '21 at 05:45

0 Answers0