Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    May 2006
    Posts
    1,683
    Thanks
    28
    Thanked 4 Times in 4 Posts

    Problem with my while loop

    Hello,

    I have a small problem with my while :

    The problem is that I want to test that the data is recieved by
    the curl function. If the url was invalid, then the next url in
    the $urls array is selected and tried.

    Problem is that the string $data will not exist until I recive it
    so the following code doesn't work.

    Should set $data to false, would that help ?

    PHP Code:
    $i 0;

    while(!
    $data) {
      
    curl_close($ch);
      
    $target $urls[$i];
      echo 
    "<br>Re-starting<br>Target_url: $target";

      
    $ch curl_init();
        
    curl_setopt($chCURLOPT_USERAGENT$userAgent);
        
    curl_setopt($chCURLOPT_URL,$target);
        
    curl_setopt($chCURLOPT_FAILONERRORtrue);
        
    curl_setopt($chCURLOPT_HEADER,0); 
        
    curl_setopt($chCURLOPT_FOLLOWLOCATIONtrue);
        
    curl_setopt($chCURLOPT_AUTOREFERERtrue);
        
    curl_setopt($chCURLOPT_TIMEOUT10);
        
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
        
    $data curl_exec($ch);
        
    $i++;

    Thanks for advice.

    PS the first curl_close($ch); will act on a previously opened
    handle. Then it has to close and failed ones.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Change the "while" loop to a "do while" loop.

    http://us3.php.net/manual/en/control...s.do.while.php

  • #3
    Senior Coder
    Join Date
    May 2006
    Posts
    1,683
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Thanks

    That fixed it


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •