0

I have this code now (after appyling fixes from this question: Check if website is available in fastest possible way)

foreach($links as $link_content)
{
                $handle = curl_init(LINK_BASE.$link_content);
                curl_setopt( $c, CURLOPT_RETURNTRANSFER, true );
                curl_setopt( $c, CURLOPT_CUSTOMREQUEST, 'HEAD' );
                curl_setopt( $c, CURLOPT_HEADER, 1 );
                curl_setopt( $c, CURLOPT_NOBODY, true );
                $content = curl_exec ($handle);
                curl_close ($handle); //warning there!!!
                $httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
                if($httpCode != 200)
                    continue; //if not, go to next link

}

Error log:

Warning: curl_getinfo(): 17 is not a valid cURL handle resource in C:\xampp\htdocs\index.php on line 82

Warning: curl_getinfo(): 18 is not a valid cURL handle resource in C:\xampp\htdocs\index.php on line 82

Warning: curl_getinfo(): 19 is not a valid cURL handle resource in C:\xampp\htdocs\index.php on line 82

I am not sure what is casuing this warning. Additionally, code doesn't work as expected. I continues loop in every case, also when website is available and returning code 200. Can you give me any tips?

1 Answer 1

1

You're calling your cURL handle $handle:

$handle = curl_init(LINK_BASE.$link_content);

but then you're trying to use $c instead in your curl_setopt calls:

curl_setopt( $c, CURLOPT_RETURNTRANSFER, true );
Sign up to request clarification or add additional context in comments.

4 Comments

I changed that - Warning: curl_getinfo(): 17 is not a valid cURL handle resource in C:\xampp\htdocs\index.php on line 83 now I see this mistake...
@Ty221 So fix the issue on that line too. You did it four times.
Nope line 83 is - $httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
You close the handle before that line, which is why it's failing. You need to do some basic troubleshooting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.