2011-06-03 72 views
-1

我试图使用phpcassa将1000000条记录从文本文件加载到Cassandra。但是在加载过程中途,我得到了以下错误。使用phpcassa将文件批量加载到Cassandra中的问题

PHP Fatal error: Maximum execution time of 30 seconds exceeded in /usr/share/php/phpcassa/columnfamily.php on line 759**

如何增加执行时间?我是否必须更改columnfamily.php中的任何参数? 请在下面找到我的代码。

<? 
    require_once('phpcassa/connection.php'); 
    require_once('phpcassa/columnfamily.php'); 
    try { 
    $servers = array("127.0.0.1:9160"); 
    $pool = new ConnectionPool("Keyspace1", $servers); 
    $column_family = new ColumnFamily($pool, 'Product'); 
    $cnt=0; 
    $files = fopen("dump.txt", "r"); 

    $mtime = microtime(); 
    $mtime = explode(" ",$mtime); 
    $mtime = $mtime[1] + $mtime[0]; 
    $starttime = $mtime; 

    while (!feof($files)) { 
     $line = fgets($files); 
     $keyname="P".$cnt; 
     $split_line = explode("," , $line); 
     for ($i=0;$i<count($split_line);$i++) { 
      //echo $split_line[$i]; 
      $column_family->insert(
       $keyname, array(
        'code' => $split_line[0] , 
        'pname' => $split_line[1] , 
        'price' => $split_line[2] 
       ) 
      ); 
     } 
     $cnt += 1; 
    } 
    $mtime = microtime(); 
    $mtime = explode(" ",$mtime); 
    $mtime = $mtime[1] + $mtime[0]; 
    $endtime = $mtime; 

    fclose($files); 

    $totaltime = ($endtime - $starttime); 
    echo "$cnt keys loaded in ".$totaltime." seconds"; 

    } 
    catch (Exception $e) 
    { 
     echo 'Exception: ' . $e->getMessage(); 
    } 
?> 

回答

2

尝试,并添加到您的脚本的顶部: set_time_limit(0);

0

set_time_limit。更一般地说,在Web服务器环境中进行批量加载(这是什么,对不对?)并不是最好的主意。这两个都不是用一个线程来完成的。但是,对于仅仅一百万行,我想,这将充分发挥作用。

0

请在php.ini文件中增加max_execution_time限制。 这将避免PHP Fatal error: Maximum execution time of 30 seconds。 默认情况下,Web服务器上的最长执行时间保持在30秒。

您可以更改此金额以便为服务器上的某些执行提供更多时间。

max_execution_time = 1200;