PHP timeouts (help, how to stop?)

Discussion in 'PHP' started by x11joex11, Jan 15, 2008.

  1. #1
    Hey I have a question, I'm running a script located here.

    http://dnfinder.net/rentacoder/alib...ompanies.html&step=3&debug=0&display=0&test=0

    It basically crawls the site alibaba for information, but eventually the script will just stop. I looked into the issue and it appeared to be the time limit. I fixed that but now the script is stopping again, but without warning. It seems when the server is making a connection to alibaba and it takes too long to do so, more then 5 seconds, (or for that matter if no data is being sent on the connection to keep it alive within 5 seconds, it just drops.) I have no idea how to deal with this? Can someone point me in the right direction?
     
    x11joex11, Jan 15, 2008 IP
  2. hostingcoupon

    hostingcoupon Peon

    Messages:
    447
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    hostingcoupon, Jan 15, 2008 IP
  3. rkquest

    rkquest Well-Known Member

    Messages:
    828
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    140
    #3
    rkquest, Jan 15, 2008 IP
  4. x11joex11

    x11joex11 Peon

    Messages:
    106
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I've already seen http://www.php.net/set_time_limit, I should have posted that it has nothing to do with that. That was another problem that I took care of. The problem now is the dropping of the connection if no data is received within a certain time frame. For example make a php program that is doing a bunch of connections to 100's of sites, but DON'T have it display the results as it grabs it. Because nothing is being sent to the users browser while this is happening it closes the connection! Hence my problem.

    I was looking into the .ini stuff, think this might be it? always_populate_raw_post_data as boolean , I doubt it is, but will play around with it, anyone else have any ideas (try re-creating this yourself).
     
    x11joex11, Jan 15, 2008 IP
  5. x11joex11

    x11joex11 Peon

    Messages:
    106
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Anyone got any other ideas?
     
    x11joex11, Jan 16, 2008 IP
  6. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #6
    If you think the problem is that no data is being sent to the user's browser, why not just send something once in a while? Send some spaces and flush the buffer after every few runs through your loop.
     
    SmallPotatoes, Jan 16, 2008 IP
  7. x11joex11

    x11joex11 Peon

    Messages:
    106
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I do 'do' that, that fixes the problem for a while, the problem is that I can't send any data while CURL is trying to load a page and it takes to long, since CURL halts progress until it gets what it wants, so how is it possible to keep sending data to that buffer? maybe a CURL_OPTION?
     
    x11joex11, Jan 16, 2008 IP
  8. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #8
    I think the browser terminates connection after {timeout} seconds of inactivity. You can try to insert into script

    ignore_user_abort(true);
    PHP:
    But it seems if browser is disconnected, it will not receive any further output after your Curl task completed. Maybe some headers are exist (KeepAlive xx seconds)..
     
    wmtips, Jan 16, 2008 IP
  9. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #9
    You can probably do what you want by using CURLOPT_READFUNCTION to channel the data through a custom callback function, but it will be more work. See here:

    http://curl.haxx.se/libcurl/php/examples/callbacks.html
     
    SmallPotatoes, Jan 16, 2008 IP
  10. x11joex11

    x11joex11 Peon

    Messages:
    106
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    I think you are onto something, I tried adding the command

    header('Connection: keep-alive');, but to no avail. The ignore_user_abort sounds interesting, but I need the user to see output :(, or there is no way of knowing that it finished, unless you have something to propose as a way of figuring that out?
     
    x11joex11, Jan 16, 2008 IP
  11. x11joex11

    x11joex11 Peon

    Messages:
    106
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Oh didn't see your post small until after I posted, looking into it now*
     
    x11joex11, Jan 16, 2008 IP
  12. x11joex11

    x11joex11 Peon

    Messages:
    106
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    How do I use CURLOPT_READFUNCTION, it only shows me write_function use on the link you sent, not entirely sure, can you show me some code?
     
    x11joex11, Jan 16, 2008 IP
  13. x11joex11

    x11joex11 Peon

    Messages:
    106
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Does anyone know how to use CURLOPT_READFUNCTION? Google can't seem to find anything... Thanks in advance!! (Really need help, stuck on job :()

    I assumed I would do code like this.

    curl_setopt($curl, CURLOPT_READFUNCTION, 'read_function');
    PHP:
    and for it's function

    //CURL CALL BACK FUNCTIONS----------------------------------------------------
    function read_function($ch,$string)
    {
        $length = strlen($string);
        echo "Received $length bytes<br />\n";
        return $length;
    }
    PHP:
    but nothing happened or showed... I then tried write CURLOPT_WRITEFUNCTION but that was just weird, while it outputed data it seems like it screwed up my return transfer, not sure why.
     
    x11joex11, Jan 17, 2008 IP
  14. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Sorry, I think it is writefunction and not readfunction. It may be the case that the data is sent to your function in lieu of via the return transfer method, so you may need to accumulate it there.

    It has been a really long time since I've dealt with this so my recollections are a bit hazy (and maybe useless).
     
    SmallPotatoes, Jan 17, 2008 IP