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();
}
?>
Please increase the
max_execution_time
limit inphp.ini
file. This will avoidPHP 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.
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.
Try and add this to top of your script:
set_time_limit(0);