0

While using PHP I am taking image links from my mysql database, and echoing them out. There are 600 or so, but it keeps stopping after running 100 or so. It is not a logic error, it seems there is a setting that is stopping php from continuing the curl. Please advise which setting I should expand to allow a longer CURL thanks!

Here is what I am using now:

function file_get_contents_curl($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch,CURLOPT_BINARYTRANSFER, true);
$data = curl_exec($ch);
return $data;
}

$htmlaa = file_get_contents_curl($getimagefrom);
$docaa = new DOMDocument();
@$docaa->loadHTML($htmlaa);

Again, it is worknig just fine but just keeps stopping after running for maybe 3 minutes.

1 Answer 1

1

You can set the curl timeout like so:

curl_setopt($ch, CURLOPT_TIMEOUT, 1000); //seconds to live

Since there are multiple factors that influence execution time you should also check out these two as well:

http://php.net/manual/en/function.set-time-limit.php

http://php.net/manual/en/info.configuration.php#ini.max-execution-time

Also please note that CURLOPT_TIMEOUT defines the amount of time that any cURL function is allowed to take to execute. You should also checkout CURLOPT_CONNECTTIMEOUT option.

Sign up to request clarification or add additional context in comments.

4 Comments

I added set_time_limit(0); to top of document but it still stops at same point each time. :(
set_time_limit does not seem to be the problem here. Did you investigate the other timeout options?
I put curl_setopt($ch, CURLOPT_TIMEOUT, 2000000); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 200000); still not working :(
please help i have no idea what to do

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.