Problem in bulk load from a file into Cassandra using phpcassa

£可爱£侵袭症+ 提交于 2019-12-13 08:51:14

问题


I am trying to load 1000000 records from a text file into Cassandra using phpcassa. But halfway through the loading process I got the following error.

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

How do I increase the execution time? Do I have to change any parameter in columnfamily.php? Please find my code below.

 <?
     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();
     }
 ?>

回答1:


Try and add this to top of your script: set_time_limit(0);




回答2:


See set_time_limit.

More generally, doing bulk load inside a web server environment (that's what this is, right?) isn't the best idea. Neither is doing it with a single thread. But for just a million rows this will work adequately, I guess.




回答3:


Please increase the max_execution_time limit in php.ini file. This will avoid PHP Fatal error: Maximum execution time of 30 seconds. By default, the maximum execution time on web servers remains at 30 seconds.

You can change that amount to provide more time for certain executions on your server.

max_execution_time = 1200;


来源:https://stackoverflow.com/questions/6224394/problem-in-bulk-load-from-a-file-into-cassandra-using-phpcassa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!