Jump to content

A few questions about cURL


AHA7

Recommended Posts

Hello,

 

I have a few questions about cURL, please!

 

1- I want to use cURL in a loop to open a few documents. Do I have to put the two functions curl_init() and curl_close() inside the loop or I can put them outside. Notice that in each iteration of the loop a different document is opened.

Example, is the following correct:

 

$ch = curl_init(); //This is outside the loop

for($i=1; $i <= $filecount; $i++)

{

$path = ${'file_location_' . $i};

curl_setopt($ch, CURLOPT_URL, $path); //The handle $ch was set outside the loop.

.

.

.

curl_exec($ch);

}

curl_close($ch); //This is outside the loop

 

2- In the loop above if CURLOPT_CONNECTTIMEOUT was set to 5 (timeout after 5 seconds), and say in the third iteration of the loop the connection times out and it fails to connect to the site, then what would happen? Would other curl_setopt() functions and the function curl_exec() be executed or not?

 

3- What does the function curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5) return when the connection times out and it fails to connect to resource? Can I use the returned value to display a customized error message when the connection times out?

 

 

Link to comment
https://forums.phpfreaks.com/topic/53148-a-few-questions-about-curl/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.