Hi,
I am working on 2MB ASCII file. I am opening and read from php script and upload the content of this ASCII file into mysql database. I am doing this via command prompt on Redhat Linux Ent 4, PHP 5.2.0 and Mysql 5.0.22. It is ok with smaller ascii file. When i try this on 2MB file, i get this error message
FATAL: emalloc(): Unable to allocate 500001 bytes
when i ran the script second time i get this
FATAL: erealloc(): Unable to allocate 2150442 bytes
Here are the Resource limit in php.ini
max_execution_time = 30
max_input_time = 60
memory_limit = 80M
Below is the script i wrote, please excuse me for coding style (i am not a programmer and i have learnt a lot in past 7 months) i hope you will be able to understand my script
#!/usr/local/php/bin/php
<?php
include("config.php"); #Database connection hadling
#To list files in a directory
$ba_ear_dir="/home/userhome/ba/ba.dpl";
$ba_ear_ascii_ext="asc";
$ba_ear_ascii_ary = glob("$ba_ear_dir/*.$ba_ear_ascii_ext");
foreach ($ba_ear_ascii_ary as $order => $file){
$order++;
#Filename
$myFile = $file;
print "Uploading file $myFile\n";
$fh = fopen($myFile, 'r');
#To read entire file until EOF....
$file_lines = array();
$i = 0;
while (!feof($fh)){
$line = fgets($fh,500000);
$file_lines[$i] = $line;
$content .= $file_lines[$i];
$i++;
}
$content = mysql_real_escape_string($content);
$title = $file_lines[0];
$titles = preg_split("/:/", $title, 3);
$title = $titles[2];
$create_date = $titles[1];
$filename = $titles[0];
#To the file size......
$filename_asc = "$filename.asc";
$file_size_asc=filesize($filename_asc);
$filename_pdf = "$filename.pdf";
$file_size_pdf=filesize($filename_pdf);
$filename_wpd = "$filename.wpd";
$file_size_wpd=filesize($filename_wpd);
#To insert title....
$query = "INSERT into ER_PROHIBIT (filename, title, content, create_date, asc_size, pdf_size, wpd_size) values ('$filename', '$title', '$content', '$create_date', $file_size_asc, $file_size_pdf, $file_size_wpd)";
#print "$query";
$queryres=mysql_query($query, $D;
if($queryres){
print "Success";
}
else{
print "error";
}
fclose($fh);
unset($content);
unset($title);
unset($titles);
unset($create_date);
unset($file_lines);
unset($file_size_asc);
unset($file_size_pdf);
unset($file_size_wpd);
unset($create_date);
}
?>