Skip to content

API queries super slow with SDK #19

@fabswt

Description

@fabswt

Hey there,

Been struggling with the API queries taking most often 22 seconds to respond. I thought the API itself was to blame, but turned out that calling the API with cURL from bash was super fast.

Figured out the culprit:

/**
 * Querying the ConvertKit API from curl like so is super fast:
 * curl https://api.convertkit.com/v3/subscribers?api_secret=APIKEY&email_address=tsyrak@hotmail.com
 *
 * BUT, calling it with the official ConvertKit PHP SDK is super slow, with
 * speeds of 22 seconds.
 *
 * Here are some comparisons.
 * Run these routes one at a time.
 */

// Official ConvertKit PHP SDK.
// SUPER SLOW. Often takes 22 seconds.
$app->get('/tests/convertkit/sdk/', function ($request, $response, $args) {
    $api = new \ConvertKit_API\ConvertKit_API(
        getenv('CONVERTKIT_API_KEY'),
        getenv('CONVERTKIT_API_SECRET'),
    );

    $subscriber_id = $api->get_subscriber_id( 'tsyrak@hotmail.com' ); // 937488134
    $response->getBody()->write(strval($subscriber_id));
    return $response;
});


// Basic file_get_contents.
// SUPER SLOW. Often takes 22 seconds.
$app->get('/tests/convertkit/file_get_contents/basic/', function ($request, $response, $args) {
    $url = "https://api.convertkit.com/v3/subscribers?api_secret="
      . getenv('CONVERTKIT_API_SECRET')
      . "&email_address=tsyrak@hotmail.com";
    $result = file_get_contents($url);

    var_dump(json_decode($result, true));

    return $response;
});

// file_get_contents with context trick.
//   See https://stackoverflow.com/a/4240241/1717535
// Fast. Under a second.
$app->get('/tests/convertkit/file_get_contents/context/', function ($request, $response, $args) {
    $url = "https://api.convertkit.com/v3/subscribers?api_secret="
      . getenv('CONVERTKIT_API_SECRET')
      . "&email_address=tsyrak@hotmail.com";
    $context = stream_context_create(array('http' => array('header'=>'Connection: close\r\n')));
    $result = file_get_contents($url, false, $context);

    var_dump(json_decode($result, true));

    return $response;
});

// with curl
// Fast. Under a second.
$app->get('/tests/convertkit/curl/', function ($request, $response, $args) {
    $url = "https://api.convertkit.com/v3/subscribers?api_secret="
      . getenv('CONVERTKIT_API_SECRET')
      . "&email_address=tsyrak@hotmail.com";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL, $url);
    $result=curl_exec($ch);
    curl_close($ch);

    var_dump(json_decode($result, true));

    return $response;
});

This is on PHP 7.4.4 and 7.4.8. (The examples use Slim Framework.)

You should be able to confirm this for yourself.

I wasted so much time with this… (Support was very slow to respond.)

For me, this makes the PHP SDK unusable. These are also serious concerns:

Please note that since ConvertKitSDK-PHP is not yet versioned, your project will always download the latest files from master every time you run composer install which may subject you to breaking changes in the future. – from the docs

Package jeremeamia/superclosure is abandoned, you should avoid using it. Use opis/closure instead. – Composer warning

I'm a paid customer, but wary of using ConvertKit because of this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions