?
Solved

max_execution_time = 0

Posted on 2011-05-02
9
Medium Priority
?
381 Views
Last Modified: 2012-05-11
hi. I am getting this error in my script

Fatal error: Maximum execution time of 60 seconds exceeded in C:\wamp\www\gblog\index.php on line 83

I am using wamp on Windows 7 and running the script with the url
http://localhost/gblog/index.php?startdate=1/1/2011&enddate=1/2/2011&keywords=Nikkei

The script is attached.
Can anyone explain what is wrong?

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
if(!isset($_REQUEST['startdate']) || !isset($_REQUEST['enddate']) ||!isset($_REQUEST['keywords']))
{
    echo "require startdate,enddate,keywords";
    exit;
}
$startdate=$_REQUEST['startdate'];
$enddate=$_REQUEST['enddate'];
$keywords=$_REQUEST['keywords'];
$keywords=str_replace(" ","+",$keywords);
/*
list($startdate,$enddate,$keywords)=$argv;

 *
 */
/*
$keywords="Tokyo+hotel+OR+ryokan+-music";
$startdate="1/1/2011";
$enddate="1/2/2011";*/
#http://www.google.com/search?hl=en&ie=UTF-8&lr=lang_en&tbm=blg&tbs=cdr:1,cd_min:1/1/2011,cd_max:1/2/2011,lr:lang_en&q=&num=100&safe=off&start=10&sa=N
$url='http://www.google.com/search?hl=en&ie=UTF-8&lr=lang_en&tbm=blg&tbs=cdr:1,cd_min:'.$startdate.',cd_max:'.$enddate.',lr:lang_en&q='.$keywords.'&num=100&safe=off';
#echo $url;
$f=fopen('output.csv','w');
 $output=getHTML($url);
preg_match_all('@<h3 class=r><a href="http://(.+?)".+?>(.+?)</h3>.+?<span class=f>(.+?)</span>(.+?)<a@',$output, $matches);
fwrite($f, '"link","title","date","source","synopsis","text"'."\n");
for($i=0;;$i++)
{
 if( !isset($matches[1][$i]) )
 {
  break;
 }
$line="";
$line.= '"http://'.$matches[1][$i].'"';
$line.= ",";
$line.= '"'.strip_tags($matches[2][$i]).'"';
$line.= ",";
$t=split("by",$matches[3][$i]);
$line.= '"'.$t[0].'"';
$line.= ",";
if(isset ($t[1]))
{
$line.= '"'.$t[1].'"';
}
else
{
    $line.= '""';
}
$line.= ",";
$line.= '"'.strip_tags($matches[4][$i]).'"';
$line.= ',"';
$line.=html2text(getHTML('http://'.$matches[1][$i]));
$line.= "\"\n";
fwrite($f, $line);
 
}
fclose($f);
function getHTML($url)
{
    $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $url);
 $agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
// curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile);
// curl_setopt($ch, CURLOPT_USERAGENT, $agent);
 // curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 // curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
 // #curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");    // Use cookie.txt for STORING cookies
 // curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
 // $output = curl_exec($ch);
 curl_setopt($ch, CURLOPT_USERAGENT, $agent);
 if(isset($proxy) && strstr($url,'google')>0)
 {
 curl_setopt($ch, CURLOPT_PROXY, $proxy[0]);
 curl_setopt($ch, CURLOPT_PROXYPORT,  $proxy[1]);
 }
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
 #curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");    // Use cookie.txt for STORING cookies

 #curl_setopt($ch, CURLOPT_COOKIE, "seen-roadblock=1;preferred_city=80");
 $output = curl_exec($ch);
 return $output;
}
function html2text($text)
{
 
$text=preg_replace('/style=".+?"/', "", $text);
       $search = array(
           "/\r/",
        "/\n/",
        '/<script.*?[^>]*>.*?<\/script>/mi',
        '/<style.*?[^>]*>.*?<\/style>/mi' ,
         '/&#\d+;/mi',
           '/[|\^#&]/mi'

    );

     $replace = array(
         '',
         '',
         '',
        '' ,
       ' ',
         ' '
    );
    $text=preg_replace($search, $replace, $text);
    $s=array(',','"',"\n");
     $text = str_replace($s, '', $text);
$text=strip_tags($text);
 


        $text= html_entity_decode($text);
       $search = array(
         '/&#\d+;/mi',
           '/[|\^#&]/mi'
           );

     $replace = array(
        '' ,
       ' ',
         ' '
    );
    $text=preg_replace($search, $replace, $text);
        return strip_tags($text);
}
?>

Open in new window

0
Comment
Question by:onyourmark
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 35510324
1. create a .htaccess file with the line 'php_value max_execution_time 300'
2. in Apache config change these lines for the virtual host:
- from
Options None
AllowOverride None
- to
Options All
AllowOverride All
3. Restart Apache.

refer
http://drupal.org/node/111985
0
 

Author Comment

by:onyourmark
ID: 35510354
Thanks. Can I ask, where do I put the htaccess file (does it just have this one line in it:
php_value max_execution_time 300
).
Also, what is the name of the apache config file and where might it be located? (I tried looking for apache.conf and apache.config).
0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
LVL 11

Expert Comment

by:mattibutt
ID: 35510602
You can put the file in the web directory if your website is the main site then you will need to put this file inside the httpdocs depends where your website resides
0
 

Author Comment

by:onyourmark
ID: 35510615
Thank you. My index.php for this app is located at
C:\wamp\www\googleblog

Is this where I should put the file? I don't see httpdocs.
0
 
LVL 12

Accepted Solution

by:
Mohamed Abowarda earned 1500 total points
ID: 35510673
If you want to make the script run without timeout add the following line in beginning of your code:
set_time_limit(0);

Open in new window


You might also want to set time limit (for example 120 seconds)
set_time_limit(120);

Open in new window

0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 500 total points
ID: 35512284
If you have a timeout of 60 seconds and you run CURL to call a foreign site for information, the thing that is happening is that the foreign site has not completed the request in 60 seconds.  In the WWW, 60 seconds is a lifetime!  I cannot really follow your code example, but I can show you how to run a CURL request that sets a timeout limit and catches the timeout condition (see the $timeout var in this code snippet).  You might try setting up a test case to see if you can figure out why the foreign server is taking so long to respond.  Perhaps you would want to contact the owners and ask if you are doing something that causes their web site to hang.
<?php // RAY_curl_example.php
error_reporting(E_ALL);



// A FUNCTION TO RUN A CURL-GET CLIENT CALL TO A FOREIGN SERVER
function my_curl
( $url
, $get_array=array()
, $timeout=3
, $error_report=TRUE
)
{
    // PREPARE THE ARGUMENT STRING IF NEEDED
    $get_string = '';
    foreach ($get_array as $key => $val)
    {
        $get_string
        = $get_string
        . urlencode($key)
        . '='
        . urlencode($val)
        . '&';
    }
    $get_string = rtrim($get_string, '&');
    if (!empty($get_string)) $url .= '?' . $get_string;

    $curl = curl_init();

    // HEADERS AND OPTIONS APPEAR TO BE A FIREFOX BROWSER REFERRED BY GOOGLE
    $header[] = "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
    $header[] = "Cache-Control: max-age=0";
    $header[] = "Connection: keep-alive";
    $header[] = "Keep-Alive: 300";
    $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
    $header[] = "Accept-Language: en-us,en;q=0.5";
    $header[] = "Pragma: "; // BROWSERS USUALLY LEAVE BLANK

    // SET THE CURL OPTIONS - SEE http://php.net/manual/en/function.curl-setopt.php
    curl_setopt( $curl, CURLOPT_URL,            $url  );
    curl_setopt( $curl, CURLOPT_USERAGENT,      'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'  );
    curl_setopt( $curl, CURLOPT_HTTPHEADER,     $header  );
    curl_setopt( $curl, CURLOPT_REFERER,        'http://www.google.com'  );
    curl_setopt( $curl, CURLOPT_ENCODING,       'gzip,deflate'  );
    curl_setopt( $curl, CURLOPT_AUTOREFERER,    TRUE  );
    curl_setopt( $curl, CURLOPT_RETURNTRANSFER, TRUE  );
    curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, TRUE  );
    curl_setopt( $curl, CURLOPT_TIMEOUT,        $timeout  );

    // RUN THE CURL REQUEST AND GET THE RESULTS
    $htm = curl_exec($curl);

    // ON FAILURE HANDLE ERROR MESSAGE
    if ($htm === FALSE)
    {
        if ($error_report)
        {
            $err = curl_errno($curl);
            $inf = curl_getinfo($curl);
            echo "CURL FAIL: $url TIMEOUT=$timeout, CURL_ERRNO=$err";
            var_dump($inf);
        }
        curl_close($curl);
        return FALSE;
    }

    // ON SUCCESS RETURN XML / HTML STRING
    curl_close($curl);
    return $htm;
}




// USAGE EXAMPLE - PUT YOUR FAVORITE URL HERE
$url = "http://finance.yahoo.com/d/quotes.csv";

// PUT YOUR ARRAY OF KEY=>VALUE PAIRS HERE
$arg = array
( 's' => 'lulu'
, 'f' => 'snl1c1ohgvt1'
)
;

// MAKE THE CALL
$htm = my_curl($url, $arg, 2, TRUE);
if (!$htm) die("NO $url");

// SHOW WHAT WE GOT
echo "<pre>";
var_dump($arg);
echo PHP_EOL . $url;
echo PHP_EOL . htmlentities($htm);
echo PHP_EOL;




// TRY ANOTHER URL WITHOUT ARGUMENTS
$url = 'http://twitter.com';
$htm = my_curl($url);
echo PHP_EOL . $url;
echo PHP_EOL . htmlentities($htm);
echo PHP_EOL;

Open in new window

0
 
LVL 12

Assisted Solution

by:Mohamed Abowarda
Mohamed Abowarda earned 1500 total points
ID: 35513905
If you are getting cURL timeout, add the following line for you proceed with the request:
(You can change the timeout as you want)
curl_setopt($ch, CURLOPT_TIMEOUT, 120); 

Open in new window

0
 
LVL 12

Assisted Solution

by:Mohamed Abowarda
Mohamed Abowarda earned 1500 total points
ID: 35513929
Add the above line before the following line in your code:
$output = curl_exec($ch);

Open in new window

0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses
Course of the Month15 days, 21 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question