Ad
Multiple Status With One Response Using CURL And Php
I have a cURL that get a response from a URL response, it is formatted like this:
{"status": "OK", "tracking_id": "363070a8-53b6-49da-a7e9-6a289a3501f2"}
Sometimes cURL executes more than once and I receive 1 to 5 different responses when I only execute it one time.
The URL I execute looks something like this:
$request = "https://precise-line.com/2/delivery/request?";
$request.= "api_key=".$api_key."&";
$request.= "user_id=".$user_id."&";
$request.= "delivery_type=".$delivery_type."&";
$request.= "route=E.+Pallares+y+Portillo&";
$request.= "street_number=110&";
$request.= "neighborhood=San+Lucas&";
$request.= "locality=Distrito+Federal&";
$request.= "administrative_area_level_1=Distrito+Federal&";
$request.= "postal_code=04030&";
$request.= "country=Mexico&";
$request.= "latlng=".$latlng."&";
$request.= "destination-route=".$destination_route."&";
$request.= "destination-street_number=&";
$request.= "destination-neighborhood=&";
$request.= "destination-locality=".$destination_locality."&";
$request.= "destination-administrative_area_level=".$destination_administrative_area_level."&";
$request.= "destination-postal_code=".$destination_postal_code."&";
$request.= "destination-country=Mexico&";
$request.= "destination-latlng=".$d_latlng."&";
$request.= "customer_email=".$customer_email."&";
$request.= "customer_phone=".$customer_phone."&";
$request.= "notification_email=&";
$request.= "notes=".$notes."&";
$request.= "dispatch=True";
error_log("Request");
error_log(print_r($request, true));
$ch_request=curl_init();
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $request);
curl_setopt($curl, CURLOPT_SSLVERSION, 1);
//curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HEADER, FALSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($curl);
curl_close ($curl);
error_log("Response");
error_log(print_r($response, TRUE));
How can I prevent cURL from executing more than once?
Ad
Answer
why do you have both $ch_request and $curl? I don't know if that makes a difference, but you should delete that line with $ch_request. Otherwise, as Dagon said, you shouldn't have multiple responses if you call it once.
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad