1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Curl Is Sometimes Very Slow And Times Out

Discussion in 'PHP' started by poddys, May 1, 2014.

  1. #1
    Sometimes but not always Curl requests for pages end up giving timing out, although the content does appear to be rendered correctly.

    There are 2 situations, firstly some plugins in Wordpress (WYSIJA in particular) and secondly a tracking script that records clicks from promotional emails that we send out, the script retrieving the page content using Curl before displaying it to the person who clicked on it.

    Looking at some of the server logs I wondered if this timing out (which causes page loads to be horrendously slow - up to and in excess of 10 seconds) was because we have no SSL defined on the server (IBM iSeries running ZendServer6) and Curl requests sometimes assume https not http.

    Any thoughts or experience on this?
     
    poddys, May 1, 2014 IP
  2. Fiverscripts

    Fiverscripts Moderator Staff

    Messages:
    1,839
    Likes Received:
    42
    Best Answers:
    1
    Trophy Points:
    370
    #2
    Hi there,

    Bear with me.. im fairly new with php programming

    I have been experimenting with this myself recently.. i am developing a web app and the app runs 2 checks back to my license server (one is to check the username on the registered license) and the other is to check the validity of the license...

    What would happen with mine is that if my server took to long to respond it would cause the page to be slow.. (similar to you) and eventually not render the code correctly..

    I found out that you can setup the parameters on your curl php call:

    CURLOPT_CONNECTTIMEOUT - The number of seconds to wait while trying to connect. Use 0 to wait indefinitely.
    CURLOPT_TIMEOUT - The maximum number of seconds to allow cURL functions to execute.

    For example:

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

    Source: http://stackoverflow.com/questions/2582057/setting-curls-timeout-in-php

    In your case i would setup a "backup" option to when this time-out occurs.. replace with something (exactly what i did with mine)..and try to trace back why the timeout is happening..

    In terms of tracking this back to why its happening?
    how have you got this setup?

    Hope this helps in some way..

    Matt
     
    Fiverscripts, May 5, 2014 IP
  3. poddys

    poddys Active Member

    Messages:
    11
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Thanks. That sounds like it could help. Since the scripts are not ours (although we could edit them if necessary) I will check if we can set defaults for Curl timeouts and handling that would be best.

    Edited to add......

    Well it doesn't look like you can set global defaults for Curl, but having set a timeout of 2 seconds and a connect timeout of 1 second (previously a timeout of 10 seconds and no connect timeout) it seems like the script executes faster. It's still slow but much faster than it was. I might experiment with shorter timeouts, since the script works, it just seems to be Curl not ending until the timeout is reached (or so it sems).
     
    Last edited: May 6, 2014
    poddys, May 6, 2014 IP
    Fiverscripts likes this.