Skip to content

CURL - massive Performance issue #10119

Closed
@aeberhard

Description

@aeberhard

Description

The following code:

<?php

$starttime = microtime(true);

$ch = curl_init();
if (0 === curl_errno($ch)) {
    $header = [];
    $header[] = 'Accept: application/vnd.github+json';
    $header[] = 'X-GitHub-Api-Version:2022-11-28';

    $options = [
        CURLOPT_URL => 'https://api.github.com/rate_limit',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_USERAGENT => 'PHP',
        //CURLOPT_CONNECTTIMEOUT => 0,
        //CURLOPT_TIMEOUT => 5,
        //CURLOPT_HTTPHEADER => $header,
        //CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
        //CURLOPT_ENCODING => '',
        //CURLOPT_DNS_USE_GLOBAL_CACHE => false,
    ];

    $log = fopen(__DIR__. '/curl.log', 'w');
    if (false !== $log) {
        $logoptions = [
            CURLOPT_VERBOSE => true,
            CURLOPT_STDERR => $log,
        ];
    }

    $curloptions = $options + $logoptions;
    curl_setopt_array($ch, $curloptions);

    $response = curl_exec($ch);
    $info = curl_getinfo($ch);

    $httpCode = (string) curl_getinfo($ch, CURLINFO_HTTP_CODE);
    echo '<pre>';
    var_dump([$httpCode, $response, $info]);
    echo '</pre>';
}


$duration = microtime(true) - $starttime;
echo "Runtime: $duration Sek.";

As you can see I tried with several Curl-Options

Resulted in this output:

Runtime: 0.76369309425354 Sek.
Runtime: 0.6199951171875 Sek.
Runtime: 0.6086049079895 Sek.
Runtime: 0.56775498390198 Sek.
Runtime: 0.54858207702637 Sek.

Performance of the Script in other PHP Versions on same Host:

PHP 7.4
Runtime: 0.11398887634277 Sek.
Runtime: 0.22311997413635 Sek.
Runtime: 0.1849901676178 Sek.
Runtime: 0.12297105789185 Sek.
Runtime: 0.16944289207458 Sek.

PHP 8.0
Runtime: 0.1490170955658 Sek.
Runtime: 0.11332702636719 Sek.
Runtime: 0.16415405273438 Sek.
Runtime: 0.19613790512085 Sek.
Runtime: 0.14559698104858 Sek.

PHP 8.1
Runtime: 0.13851690292358 Sek.
Runtime: 0.11393594741821 Sek.
Runtime: 0.10096192359924 Sek.
Runtime: 0.14624786376953 Sek
Runtime: 0.11632513999939 Sek.

In PHP 8.2 the the Curl pretransfer_time is up to 5 times bigger than in other versions.

PHP 8.0
    ["total_time"]=>
    float(0.127489)
    ["namelookup_time"]=>
    float(0.005659)
    ["connect_time"]=>
    float(0.058811)
    ["pretransfer_time"]=>
    float(0.105881)

PHP 8.2
    ["total_time"]=>
    float(0.522058)
    ["namelookup_time"]=>
    float(0.006427)
    ["connect_time"]=>
    float(0.036172)
    ["pretransfer_time"]=>
    float(0.5042)

PHP Version

PHP 8.2.0

Operating System

Windows 10 Enterprise 21H2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions