Jump to content

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

I did read the mannual, but they didn't specifically say anything about what curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, VALUE) returns when the connection times out. I have also tried to do some tests but the connection seemed to always succeed. Could not make it time out.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.