Search code examples
phpcurlphp-7php-curlcurl-multi

PHP curl_multi_getcontent Always Outputs the content


I am building a site "monitor", and have decided to utilize curl_multi_* due to the number of sites I need to monitor as well as the multiple curl pulls I need to make per iteration.

CODE:

https://gitlab.com/snippets/1739288

(too much to post here, though if needed I can)

The issue that I am running into is line 82(ish), seems to always output the content of the page, rather than assigning it to the variable $_content, and because of this, I am not able to "search" the content for the $_test_string that I need to, thus it always fails.

What am I doing wrong, and how can I get that content set to the variable so I can actually test it?


Solution

  • Your second channel setting is still using the first channel variable:

    // first handle sepcific
    curl_setopt( $_ch1, CURLOPT_RETURNTRANSFER, false );
    // second handle specific
    curl_setopt( $_ch1, CURLOPT_RETURNTRANSFER, true );
                 ^^^^^
    

    Take this moment to learn why cutting-and-pasting code is bad. If you have to write something more than once, use a function. :)