Skip to content

Problem, when using multicurl and tags #704

@juhacz

Description

@juhacz

Hi

I spent a few hours today looking for a bug in my application. It turned out that the error was in the class. It appears when we want to use multicurl and tags, and the tag is passed to the instance and we name it "id". If we name it differently, everything works fine. Below is an example that uses a multicurl to load three pages, and save it to file, two of them, are identical. When we use $instance>pid instead of $instance->id, everything works fine.

Code:

<?php
require __DIR__ . './vendor/autoload.php';

use Curl\MultiCurl;

$urls = [
    1 => 'https://www.spotify.com/pl/',
    2 => 'https://www.spotify.com/gr/',
    3 => 'https://www.spotify.com/be-fr/',
];

$multi_curl = new MultiCurl();

$multi_curl->complete(function ($instance) {
    // if I use $instance->pid all working fine
    file_put_contents($instance->id.".html", $instance->response);
});

foreach ($urls as $tag => $url) {
    $instance = $multi_curl->addGet($url);
    // if I use $instance->pid = $tag all working fine
    $instance->id = $tag;
}

$multi_curl->start();

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