Jump to content

Recommended Posts

I've got a function that gets some XML data from a server. Unfortunately the server isn't very reliable so I've used curl_setopt() with a CURLOPT_SETTIMEOUT value of 5.

 

Here's some reference code to better understand:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this -> url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$xml = curl_exec($ch);
curl_close($ch);

 

I'm unsure as what it supposed to happen. If it times-out, will $xml be false? At the moment I'm assuming that behaviour and loading the data from cache if $xml is false. The only problem is that whenever the server is unavailable, the script just takes forever to execute and doesn't seem to be timing-out at all.

 

In actual fact there's some really weird things happening which I have no idea about but I just wanted to check first that this part of the code isn't the problem because it seems like the most obvious place where things are going wrong.

Link to comment
https://forums.phpfreaks.com/topic/85831-solved-curlopt_settimeout-trouble/
Share on other sites

What's the significance of 16? I'll try it but I don't think it will make any difference as the script seems to be ignoring the timeout and waiting 20 minutes for the absent server to respond.

 

Have you had any success with using 16? What I mean is, has there been a time when the script has actually had to stop trying to connect due to a timeout?

I just had a quick look through the documentation. CURLOPT_SETTIMEOUT isn't even on the curl_setopt page so I have no idea where I got it from now.

 

From the description CURLOPT_CONNECTTIMEOUT looks like the one I want but it obviously doesn't work for some reason as I was already using it. I might just use your suggestion and go with CURLOPT_TIMEOUT to make sure the load times are snappy though.

 

Thanks though!

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.