Fatal error: Maximum execution time... HELP PLEASE!

Discussion in 'PHP' started by onproxylinecom, Jul 24, 2009.

  1. #1
    Fatal error: Maximum execution time of 30 seconds exceeded in /home2/playtwof/public_html/livio/functions/down.php on line 56

    This is the sscript .. is ussign curl to get a result ...

    
    <?php
    ini_set("display_errors",1);
    set_time_limit(5);  //this you know what gonna do
    error_reporting(E_ALL);
    $url = "$downlink";
    $curllink = curl_init($url);
    
    curl_setopt($curllink, CURLOPT_HEADER, FALSE);
    curl_setopt($curllink, CURLOPT_RETURNTRANSFER, TRUE);
    
    $source = curl_exec($curllink);
    curl_close ($curllink);
    
    $pos = strpos($source,'(%Form style=');
    $pastelink='';
    
    while ($source[$pos]!="'") {
    	$pastelink .= $source[$pos];
    	$pos++;
    }
    $pastelink= trim(str_replace('!!!','"',$pastelink));
    $pastelink= trim(str_replace('(%','<',$pastelink));
    $pastelink= trim(str_replace('%)','>',$pastelink));
    
    echo $pastelink;
    
    ?>
    
    Code (markup):
    My question si .. HOW DO I PASS THE ERROR? i mean if the curl can't find the result in requested page how do i close the script and show an error and the page to continue loading normaly ?


    Please READ CLOSE before you answer!
     
    Last edited: Jul 24, 2009
    onproxylinecom, Jul 24, 2009 IP
  2. khthelegend

    khthelegend Active Member

    Messages:
    274
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #2
    try to divide this loop before execution
    while ($source[$pos]!="'") {
    $pastelink .= $source[$pos];
    $pos++;
    }

    error shown because of memory limit.
     
    khthelegend, Jul 24, 2009 IP
  3. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Better yet actually see if $source had been returned as a false (failed connection).

    ie: if($source === false) { ... }

    cuz you may have a problem with the connection and not so much with the code. And since it says there was a time out, I'm guessing your url might be invalid.
     
    kblessinggr, Jul 24, 2009 IP
  4. onproxylinecom

    onproxylinecom Guest

    Messages:
    295
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    is not working .... in the page i curl is no more that form is just say the file is no more avaible ... and the curl cand read the form because there is not
     
    onproxylinecom, Jul 24, 2009 IP
  5. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #5
    When you said this:

    Fatal error: Maximum execution time of 30 seconds exceeded in /home2/playtwof/public_html/livio/functions/down.php on line 56

    That's not a memory limit, that's a time-out, means the script or the url it connected to, took too long to return a response. depending on the response from curl, you might have caused yourself an infinite loop.
     
    kblessinggr, Jul 24, 2009 IP
  6. onproxylinecom

    onproxylinecom Guest

    Messages:
    295
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    It's a time out because the script cand fint the begin and the end of the tags on the curled page... and he is searching...searching..and searching until is timed out .... If the script find the begin and the end of the tag is geting the result fast.. max 2 seconds
     
    onproxylinecom, Jul 24, 2009 IP
  7. onproxylinecom

    onproxylinecom Guest

    Messages:
    295
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    no is not a failed conection...is because is not finding the begin and the eng of the tags i've search in curled page
     
    onproxylinecom, Jul 24, 2009 IP
  8. Tarkan

    Tarkan Peon

    Messages:
    491
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #8
    look up max execution time in php.net and find the set_ini for changing it.
     
    Tarkan, Jul 24, 2009 IP
  9. onproxylinecom

    onproxylinecom Guest

    Messages:
    295
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    :|...are you joking ? i use set_time_limit(); for time limit ... not necasary to change it from php.ini ... i asked for something else.

    Please READ CLOSE before you answer!
     
    onproxylinecom, Jul 24, 2009 IP
  10. zandigo

    zandigo Greenhorn

    Messages:
    71
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #10
    Oh right, I will read the thread really close so that I will not get scolded by you :)

    So your question is if the curl can't find the result in requested page, blah blah blah,.. I have 2 things for you to clear up.

    1. If curl cannot connect to url server, so kblessing is right, just use fail connection check.
    2. If curl is successfully executed, which means $source has some kind of string, the question would never be "curl can't find result". Because curl did get some response back.
    At this point, everything would be fairly easy. If the string you want to find is not in $source, do not use while loop! (As you say he keeps searching... searching). If you want to take a portion out of a string, I suggest using substr.

    My raw code would be as below, modify, or correct any errors if there are. I dont use while loop, so 'he' will not keep searching this time :D.
    
    if ($source !== false) {
    	// curl returned some kind of value, connection succeeded
    
    	// find string (%Form styld=';
    	$pos = strpos($source,'(%Form style=');
    
    	if ($pos !== false) {
    		//string (%Form styld=' is found
    		
    		// because you just want string after position $pos, we will cut the string from that position
    		$source=substr($source, $pos);
    
    		// find the first occurence of  ' in new $source
    		$end= strpos($source, "'");
    	
    		if ($end !== false) {
    			// if  ' is found
    			$pastelink= substr($source, 0, $end + 1);
    
    		} else { 
    			// if ' is not found
    			echo "' is not found in $source";
    		{
    
    	} else {
    		// string (%Form styld=' is not found
    		echo "string (%Form styld=' is not found";
    	}
    
    } else {
    	// no connection
    	echo "Requested page is not available";
    }
    PHP:
    Hope that helps with your problem.
     
    zandigo, Jul 24, 2009 IP
  11. onproxylinecom

    onproxylinecom Guest

    Messages:
    295
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Just before i sow your reply i've made the script :
    
    <?php
    ini_set("display_errors",1);
    set_time_limit(5);
    error_reporting(E_ALL);
    $url = "$downlink";
    $curllink = curl_init($url);
    
    curl_setopt($curllink, CURLOPT_HEADER, FALSE);
    curl_setopt($curllink, CURLOPT_RETURNTRANSFER, TRUE);
    
    $source = curl_exec($curllink);
    curl_close ($curllink);
    
    $pos = strpos($source,'(%Form style=');
    
    if(!is_bool(strrpos($source,"(%Form style=")))
    {
    $pastelink='';
    
    while ($source[$pos]!="'") {
    	$pastelink .= $source[$pos];
    	$pos++;
    }
    $pastelink= trim(str_replace('!!!','"',$pastelink));
    $pastelink= trim(str_replace('(%','<',$pastelink));
    $pastelink= trim(str_replace('%)','>',$pastelink));
      
    echo "$pastelink";
    }
    else
    {
    echo "Sorry the result cannot be found!";
    }
    ?>
    
    Code (markup):
    I'm a php beginer a friend helps me sometimes but now i whanned to make it on my own... Thanks aniway to all users that sow my topic and tryed to help me ... and :eek: Sorry for my english :p i'm not a master in english grammar !

    Thanks again guys!
     
    onproxylinecom, Jul 24, 2009 IP
  12. zandigo

    zandigo Greenhorn

    Messages:
    71
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #12
    while ($source[$pos]!="'") {
    	$pastelink .= $source[$pos];
    	$pos++;
    }
    
    PHP:
    I just dont want to be picky but if in the string, there is no ', after "form style", your while loop will still get Fatal error again.

    But if the php file that generate the response is yours, you can ensure it will not run into the error. (but, extra care is always necessary, pal, use substr hehe :D).

    Anyway, use any command you want as long as it works fine.
     
    zandigo, Jul 24, 2009 IP
  13. onproxylinecom

    onproxylinecom Guest

    Messages:
    295
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #13
    for moment is ok..:p:)if i'll have problems again i'll post again :p ;)) Thanks again;)
     
    onproxylinecom, Jul 24, 2009 IP
  14. Goramba

    Goramba Peon

    Messages:
    128
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Just a heads up, if you have execution time problems you can try putting:
    set_time_limit(0);

    at the top of your page. That will set the php timeout to infinite but iis/apache may have its own.
     
    Goramba, Jul 24, 2009 IP