如何在csv文件中放入大记录

I am creating a csv file but there are 9700 records in database but around 6800 rows are inserting in csv file, please advise how can I do it, i have heard about saving data in temp file and then putting it in csv , i am not sure how to do that

$valArr = $fieldArr['field_value'];
if(!empty($arrvalH_VH))
    $valArr = array_merge($fieldArr['field_value'],$arrvalH_VH);
if(!empty($field_value_arr))
    $valArr = array_merge($valArr,$field_value_arr);
fputcsv($file, $valArr);

Thanks

With the long processes like data import/export, there is a good probability that PHP maximum execution timeout is terminating the script before completion. Execution timeout can be increased by following setting in php.ini.

    max_execution_time = 360 // Timeout value is in seconds

As an alternate the same setting can be changed from PHP code as below:

    ini_set('max_execution_time', '360');

NOTE: If restricted by server admin, you will not be able to set max_execution_time. This is the case with most shared hosting providers.