1

I have a PHP website and one of the pages I use makes a CURL call to another server. Now this server need about 45 seconds to respond, and there is nothing I can do about it.There is actually 2 step to get the information, the first step is to send the request to update the information (this takes about 43 seconds) and after I need to send another request to get the data back (normally takes 2-5 sec).

My server is on GoDaddy and obviously sometimes it timeout (CGI Timeout) because I think it's normally 30 seconds.

This script (asking the request + getting the data back), is normally triggered overnight via cron job however it can be triggered during the day.

So I was wondering: what would be the best way to split the information to avoid timeout issues?

I was thinking of just sending theupdate request and don't care about the result. Then, about a minute after, I would send a request to get back the data. However, I have no idea if it's even possible to do a timer in PHP, and if so, would the page timeout anyways?

Thanks!

2 Answers2

0

You can set a timeout value in your PHP code to allow more time.

Setting Curl's Timeout in PHP

If you want to run the files separately, I would set up a separate cron job for the second file.

Community
  • 1
  • 1
ckimbrell
  • 537
  • 3
  • 9
  • Thanks for your reply. The problem is not with the PHP file but with the CGI Timeout... I already use set_time_limit(120); – Steven Sicard Nov 05 '15 at 18:50
  • Have you increased the CURLOPT timeout settings? I have updated the link in my answer. – ckimbrell Nov 05 '15 at 18:53
  • Yes, also did that,(See below) – Steven Sicard Nov 05 '15 at 19:08
  • If it is shared hosting, looks like you don't have the ability to increase the timeout. Have you tried this on a different server to verify it works so you can pinpoint it to the GoDaddy server? – ckimbrell Nov 05 '15 at 19:55
  • Thanks for your answer. I did contact GoDaddy and they told me exactly this (cannot increase timeout). I did not try it on a different server. I was more trying to find a solution other then paying for a dedicated server :) – Steven Sicard Nov 05 '15 at 19:59
  • I understand. Sorry for the bad news. – ckimbrell Nov 05 '15 at 20:17
0

Use CURLOPT_CONNECTTIMEOUT to increase server response time.

CURLOPT_CONNECTTIMEOUT  

The number of seconds to wait while trying to connect. Use 0 to wait indefinitely.

And then you need to use CURLOPT_TIMEOUT to get working the option CURLOPT_CONNECTTIMEOUT.

Something like this,

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0); // 0 for wait infinitely, not a good practice

curl_setopt($ch, CURLOPT_TIMEOUT, 400); //in seconds

You can set it in micro seconds as well , like so,

 CURLOPT_TIMEOUT_MS
monirz
  • 534
  • 5
  • 14