I have a php script which writes csv files to disk, this is the function:
function fputcsv_content($fp, $array, $delimiter=",", $eol="\n") {
$line = "";
foreach($array as $value) {
$value = trim($value);
$value = str_replace("\r\n", "\n", $value);
if(preg_match("/[$delimiter\"\n\r]/", $value)) {
$value = '"'.str_replace('"', '""', $value).'"';
}
$line .= $value.$delimiter;
}
$eol = str_replace("\\r", "\r", $eol);
$eol = str_replace("\\n", "\n", $eol);
$line = substr($line, 0, (strlen($delimiter) * -1));
$line .= $eol;
return fputs($fp, $line);
}
The server is an AWS instance, CentOS 7 and PHP version is 7.2
Server specs: 4GB RAM 32GB SWAP 2 cores, 2.5GHZ
When files are large, (3GB, 4GB) the writing process is very slow, (1MB every 2 or 3 seconds).
Is there any setting in php.ini or apache config that controls this fputs/fwrite function?
I've seen an output_buffer setting in php.ini (currently set to 4096) but I doubt it has anything to do.
Thanks!