Problem in bulk load from a file into Cassandra us

2019-09-21 10:09发布

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

3条回答
老娘就宠你
2楼-- · 2019-09-21 10:24

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;
查看更多
太酷不给撩
3楼-- · 2019-09-21 10:38

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.

查看更多
Anthone
4楼-- · 2019-09-21 10:39

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

查看更多
登录 后发表回答