Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP cURL Warning during curl_multi_add_handle

Tags:

php

My PHP code

    $urlArray = array('http://firsturl.com', 'http://secondurl.com');
    $nodeCount = count($urlArray);
    $chContainter = array();
    $mh = curl_multi_init();
    for($i = 0; $i < $nodeCount; $i++) {
        $chContainter[$i] = curl_init();
        curl_setopt($chContainter[$i], CURLOPT_URL, $urlArray[$i]);
        curl_setopt($chContainter[$i], CURLOPT_HEADER, 0);
        curl_setopt($chContainter[$i], CURLOPT_RETURNTRANSFER,1);
        curl_multi_add_handle($mh,$chContainter[$i]);
    } 

is generating the following warning

Warning: (null)(): 4 is not a valid cURL handle resource in Unknown on line 0

Warning: (null)(): 5 is not a valid cURL handle resource in Unknown on line 0

I did some debugging and found out the warning was generated when I try to add curl handle to the $mh.

Please help. Thanks.

like image 949
Jeffery H. Avatar asked Oct 19 '25 04:10

Jeffery H.


1 Answers

Make sure to initialize curl_multi_init() only after you initialized your curl_init() sessions, otherwise you'll get that error.

like image 50
Walter Avatar answered Oct 21 '25 19:10

Walter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!