[英]Problem in bulk load from a file into Cassandra using phpcassa
我正在嘗試使用 phpcassa 將文本文件中的 1000000 條記錄加載到Cassandra中。 但是在加載過程的中途,我收到了以下錯誤。
PHP 致命錯誤:/usr/share/php/phpcassa/columnfamily.php 在第 759 行中超過了 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();
}
?>
嘗試將其添加到腳本頂部: set_time_limit(0);
請增加php.ini
文件中的max_execution_time
限制。 這將避免PHP Fatal error: Maximum execution time of 30 seconds
。 默認情況下,web 服務器上的最大執行時間保持在 30 秒。
您可以更改該數量,以便為服務器上的某些執行提供更多時間。
max_execution_time = 1200;
更一般地說,在 web 服務器環境(就是這樣,對嗎?)中進行批量加載並不是最好的主意。 也不是用一個線程來做的。 但我猜,對於一百萬行,這將足夠工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.