Fyorl Posted January 13, 2008 Share Posted January 13, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/85831-solved-curlopt_settimeout-trouble/ Share on other sites More sharing options...
tinker Posted January 13, 2008 Share Posted January 13, 2008 In your example your using CURLOPT_CONNECTTIMEOUT, in my limited experience with cURL I use: curl_setopt($ch, CURLOPT_TIMEOUT, 16); Quote Link to comment https://forums.phpfreaks.com/topic/85831-solved-curlopt_settimeout-trouble/#findComment-438063 Share on other sites More sharing options...
Fyorl Posted January 13, 2008 Author Share Posted January 13, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/85831-solved-curlopt_settimeout-trouble/#findComment-438065 Share on other sites More sharing options...
tinker Posted January 13, 2008 Share Posted January 13, 2008 16 is just a sweet arbitrary value, i've got mine high at the moment because actual connections seem to be taking a long time for me, but the original tutorial was to 3, meaning 4 seconds, go figure? However CURLOPT_TIMEOUT works for me! Quote Link to comment https://forums.phpfreaks.com/topic/85831-solved-curlopt_settimeout-trouble/#findComment-438087 Share on other sites More sharing options...
Fyorl Posted January 13, 2008 Author Share Posted January 13, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/85831-solved-curlopt_settimeout-trouble/#findComment-438095 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.