-1

我正在尝试使用 phpcassa 将文本文件中的 1000000 条记录加载到Cassandra中。但是在加载过程的中途,我收到了以下错误。

PHP 致命错误:在第 759 行的 /usr/share/php/phpcassa/columnfamily.php 中超过了 30 秒的最大执行时间**

如何增加执行时间?我必须更改任何参数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();
     }
 ?>
4

3 回答 3

2

尝试将此添加到脚本的顶部: set_time_limit(0);

于 2011-06-09T15:07:31.243 回答
0

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

您可以更改该数量,以便为服务器上的某些执行提供更多时间。

max_execution_time = 1200;
于 2013-06-07T18:04:14.907 回答
0

set_time_limit

更一般地说,在 Web 服务器环境中进行批量加载(就是这样,对吗?)并不是最好的主意。也不是用一个线程来做的。但我猜,对于一百万行,这将足够工作。

于 2011-06-09T15:13:17.473 回答