timeout part of a script

Discussion in 'PHP' started by Adfuel, Feb 12, 2010.

  1. #1
    Silly question

    Im using

    implode('', file($url);

    in a loop to open pages and check for backlinks.

    Is there a way to make it only check for 5 seconds and then go to the next $url?
     
    Adfuel, Feb 12, 2010 IP
  2. ProtegeSales

    ProtegeSales Guest

    Messages:
    88
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can use this with safe_mode ON only.

    
    if(!ini_get('safe_mode')) {
        set_time_limit(240);
        ini_set('max_input_time', 300);
    }
    
    PHP:
    If Safe Mode is on, then never mind that - I would be helpless.

    You can check if safe_mode is on, in your php.ini or by using

    
    php_info();
    
    PHP:
     
    ProtegeSales, Feb 12, 2010 IP
  3. Adfuel

    Adfuel Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I dont think that will work.

    I want to do something like this:

    while (looping though $urls){

    while( <less than 5 seconds or $content is found> ){
    $content = implode('', file($url));
    }

    }

    is there a way to do that?
     
    Adfuel, Feb 12, 2010 IP
  4. ProtegeSales

    ProtegeSales Guest

    Messages:
    88
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Well, there's no need to set a time limit, rather than how far microtime() can be delimited. Use something along these lines.

    
    
    $time = microtime();
    $startTime = // MICROTIME+HOWLONGFROMTHEN 
    for ($i = $time; $i >= $startTime; $i--):
    
          if ($CONTENT) {
            echo "Something here.";
          } else {
            $startTime--;
            if ($startTime<=0):
              // Loop went out the back door
              break;   // escape from the for loop
            }
          }
    }
    
    PHP:
     
    ProtegeSales, Feb 12, 2010 IP
  5. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #5
    Look into moving to cURL for retrieving the pages. cURL has among other goodies, connection and read timeout arguments available.
     
    joebert, Feb 13, 2010 IP
  6. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Why aren't you using

    file_get_contents($url)
    PHP:
    ?
     
    SmallPotatoes, Feb 13, 2010 IP
  7. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #7
    I believe he wants to return an array (file) instead of a string (file_get_contents) which is why he used implode later on in the code.
     
    danx10, Feb 13, 2010 IP
  8. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #8
    But he had implode('', file(__)) on a single line!
     
    SmallPotatoes, Feb 13, 2010 IP