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!
try to divide this loop before execution while ($source[$pos]!="'") { $pastelink .= $source[$pos]; $pos++; } error shown because of memory limit.
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.
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
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.
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
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
:|...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!
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 . 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.
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 Sorry for my english i'm not a master in english grammar ! Thanks again guys!
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 ). Anyway, use any command you want as long as it works fine.
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.