php-multi-curl icon indicating copy to clipboard operation
php-multi-curl copied to clipboard

why the first url always return null?

Open cloudstoneme opened this issue 8 years ago • 2 comments

Example Code:

$urls = array('http://google.com', 'https://twitter.com');
$mc = JMathai\PhpMultiCurl\MultiCurl::getInstance();
$calls = array();
foreach($urls as $url) {
    $handle = curl_init($url);
    curl_setopt( $handle, CURLOPT_NOBODY, true );
    curl_setopt( $handle, CURLOPT_HEADER, false );
    $calls[] = $mc->addCurl($handle);
}

$r = array();
foreach($calls as $email => $call) {
$r[] = $call->code;
}

var_dump($r);

Hi,

the result of first url will always return null, why? did I missing anything or is it a bug?

Thanks.

cloudstoneme avatar Aug 06 '16 09:08 cloudstoneme

Your code works if you add this option

curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);

So I guess it is a bug somewhere.

bramley avatar Aug 12 '16 12:08 bramley

Thanks @bramley. Looks like addUrl() sets it but addCurl() does not. I will update this unless I get a PR for it first. 👍

jmathai avatar Aug 12 '16 15:08 jmathai