myDBR Update from 6.7.0 (build 4947) to 6.7.2 (build 4972) seems to have caused a problem using cURL

(8 posts) (2 voices)

Tags:

No tags yet.

  1. shem, Member

    Before we updated our myDBR version, it worked.
    We would use the following cURL from our PHP code to run a report:

       public static function generateReportFromUrl(string $url, string $report_type = null)
    {
    if (!is_null($report_type)) {
    $url = $url . "&export=" . $report_type;
    }
    $ch = curl_init();
    if (!(is_resource($ch) && get_resource_type($ch) === 'curl'))
    {
    throw new \Exception("cURL Error: ailed to initialize cURL.");
    }
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Note: THIS SETTING DOES NOT SOLVE THE PROBLEM
    // Get the config setting for the global myDBR user id and password
    $userId = Yii::$app->params['mydbr_global_user_id'];
    $userPassword = Yii::$app->params['mydbr_global_user_password'];
    $credentials = $userId . ":" . $userPassword; curl_setopt($ch, CURLOPT_USERPWD, $credentials);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-MYDBR-AUTH: 1'));
    $file = curl_exec($ch);
    if ($file === false)
    {
    $error_msg = curl_error($ch);
    $error_no = curl_errno($ch);
    curl_close($ch);
    // Exception will be handled by parent BaseAutomationException
    throw new \Exception("cURL Error: [$error_no] - $error_msg");
    }
    else
    {
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    if ($httpCode >= 400) {
    throw new \Error("Report Request Error. HTTP error " . $httpCode);
    }
    else if ($file == "") {
    // Note For some reason Curl returns empty on my local VM
    throw new \Error("Report Request Error. Unable to retrieve report data");
    }
    }
    return $file;
    }

    After we update the version, the content from myDBR is returning the empty string without triggering errors.
    Here is the info returned from curl_info()

    (
    [url] => https://apps.verifacto.com/mydbr/report.php?r=sp_DBR_removed_cpi_full_report&h=80dab4b126b246482eb51a48aed078d028074c5c900f2741bbb383131a0db91a&p1=%60tx-ctc%60&u2=((ALL))&u3=((ALL))&u4=((ALL))&u5=((ALL))&u6=2023-11-16&u7=2023-11-16&hdr=0&export=CSV
    [content_type] => text/html; charset=UTF-8
    [http_code] => 302
    [header_size] => 588
    [request_size] => 382
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.213583
    [namelookup_time] => 0.000325
    [connect_time] => 0.000789
    [pretransfer_time] => 0.020738
    [size_upload] => 0
    [size_download] => 0
    [speed_download] => 0
    [speed_upload] => 0
    [download_content_length] => 0
    [upload_content_length] => -1
    [starttransfer_time] => 0.213558
    [redirect_time] => 0
    [redirect_url] =>
    [primary_ip] => 44.208.208.71
    [certinfo] => Array
    (
    )

    [primary_port] => 443
    [local_ip] => 192.168.10.105
    [local_port] => 45778
    [http_version] => 2
    [protocol] => 2
    [ssl_verifyresult] => 0
    [scheme] => HTTPS
    [appconnect_time_us] => 20700
    [connect_time_us] => 789
    [namelookup_time_us] => 325
    [pretransfer_time_us] => 20738
    [redirect_time_us] => 0
    [starttransfer_time_us] => 213558
    [total_time_us] => 213583
    )

    Please note that if we copy the above URL and paste it into the browser the report content is returned as expected.
    https://apps.verifacto.com/mydbr/report.php?r=sp_DBR_removed_cpi_full_report&h=80dab4b126b246482eb51a48aed078d028074c5c900f2741bbb383131a0db91a&p1=%60tx-ctc%60&u2=((ALL))&u3=((ALL))&u4=((ALL))&u5=((ALL))&u6=2023-11-16&u7=2023-11-16&hdr=0&export=CSV

    But again, before we updated our myDBR version, even using cURL worked as expected.

  2. myDBR Team, Key Master

    HTTP code 302 means that there is a redirect in the request. To make cURL to follow the redirect, add the CURLOPT_POSTFIELDS option to the call.

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

    if you want to examine the final destination (cause of the redirect), you can use call

    curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);

    to get the final destination.

    --
    myDBR Team

  3. shem, Member

    In the words of our lead developer, "the use of
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    to accommodate the redirect does not fix this."

    And as I mentioned before, nothing that I know of changed when it was working last week until this week when we updated the myDBR version.

    Please help since this is a problem on our production machine for all clients that use the feature that calls the cURL.

  4. myDBR Team, Key Master

    What is the result after the CURLOPT_FOLLOWLOCATION option?

    If the browser is able to fetch the CSV file, so should the cURL with correct options.


    myDBR Team

  5. shem, Member

    The curl info after
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    is
    (
    [url] => https://apps.verifacto.com/mydbr/report.php?r=sp_DBR_removed_cpi_full_report&h=80dab4b126b246482eb51a48aed078d028074c5c900f2741bbb383131a0db91a&p1=%60tx-ctc%60&u2=((ALL))&u3=((ALL))&u4=((ALL))&u5=((ALL))&u6=2023-11-16&u7=2023-11-16&hdr=0&export=CSV
    [content_type] => text/html; charset=UTF-8
    [http_code] => 302

    [header_size] => 588
    [request_size] => 382
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.213583
    [namelookup_time] => 0.000325
    [connect_time] => 0.000789
    [pretransfer_time] => 0.020738
    [size_upload] => 0
    [size_download] => 0
    [speed_download] => 0
    [speed_upload] => 0
    [download_content_length] => 0
    [upload_content_length] => -1
    [starttransfer_time] => 0.213558
    [redirect_time] => 0
    [redirect_url] =>
    [primary_ip] => 44.208.208.71
    [certinfo] => Array
    (
    )

    [primary_port] => 443
    [local_ip] => 192.168.10.105
    [local_port] => 45778
    [http_version] => 2
    [protocol] => 2
    [ssl_verifyresult] => 0
    [scheme] => HTTPS
    [appconnect_time_us] => 20700
    [connect_time_us] => 789
    [namelookup_time_us] => 325
    [pretransfer_time_us] => 20738
    [redirect_time_us] => 0
    [starttransfer_time_us] => 213558
    [total_time_us] => 213583
    )

    I agree with you that
    "If the browser is able to fetch the CSV file, so should the cURL with correct options."
    Thats why we need your help.
    Again, it was working before we updated myDBR from 6.7.0 (build 4947) to 6.7.2 (build 4972)

  6. myDBR Team, Key Master

    We'll take a look at it.

    --
    myDBR Team

  7. myDBR Team, Key Master

    Shem,
    you can update to the latest build that will fix the issue. Note that you should use the CURLOPT_FOLLOWLOCATION option.

    Thank you for reporting the issue.
    --
    myDBR Team

  8. shem, Member

    Thank you very much.
    It seems to have worked.


Reply

You must log in to post.