Search code examples
phpcurlcurl-multi

PHP - stop all curl_multi requests at a certain point


I have a php script that uses curl_multi to make multiple requests at the same time.

It accesses several of my sites in search for a defined value.

Now the problem that I have is that the curl requests should stop if it found the value I'm searching for on one of the sites.

Let's say I parse 1000 pages for the word stackoverflow. The script accesses those pages with curl_multi and 10 requests at a time. Let's say the script found the word stackoverflow on the 589th page, it should stop all further requests now.

Is that somehow possible?


Solution

  • somewhere in your code, your have a loop that processes the individual curl handles. In that loop, you insert the following logic.

    if(shouldStop()) {
        break;
    }