Good morning!
(My apologies for sending to both lists, I found emalloc() info on both
PHP and MySQL that might be applicable and could not make a good call as
to where this might be more appropriate)
We are attempting to return a rather large file from a set of queries to
MySQL via PHP. Each time the query completes we are freeing the result
(mysql_free_result) so that we do not get memory errors, but at about 20
MB (tested multiple times) we get ...
FATAL: emalloc(): Unable to allocate 2 bytes
Here is the code ....
<?php
//connect to and select database
include("dbconnect.cali.php");
//include test data vs. real data
include("choose_data.cali.php");
// get list of originating RC
$qorg = "SELECT DISTINCT(originating) AS original FROM " .
$curtblRCscope . " ";
if(!($dborg = mysql_query($qorg, $dbconnect))){
print("MySQL Reports: " . mysql_error() . "\n");
exit();
}
// create array so memory from query can be freed
$a = 0;
while ($org = mysql_fetch_object($dborg)){
$orig_array[$a] = $org->original;
$a++;
}
mysql_free_result($dborg);
$orig_count = count($org_array);
if ($curtblRC == "tblRC"){
$curpath = "/var/lib/apache/htdocs/callscope/output/";
} else {
$curpath = "/usr/feynman/lcs/";
}
if (!($npanxxfile =
fopen($curpath."npanxx.cali.".date("Ymd").".txt","w+"))){
print("Failed to open file!\n");
exit();
}
//file was opened
for($i = 0; $i < $orig_count; $i++){ // start writing loop
//get npanxx list
$qnpanxx = "SELECT DISTINCT c.originating as origin, c.terminating as
termination, a.npanxx as o_npanxx, b.npanxx as t_npanxx ";
$qnpanxx .= "FROM ".$curtblRC." a, ".$curtblRC." b,
".$curtblRCscope." c ";
$qnpanxx .= "WHERE a.RCname = '" . $orig_array[$i] . "' ";
$qnpanxx .= "AND a.RCname = c.originating ";
$qnpanxx .= "AND b.RCname = c.terminating ";
$qnpanxx .= "ORDER BY c.originating, c.terminating, a.npanxx,
b.npanxx ";
//$qnpanxx .= "LIMIT 5 "; // for test purposes jb
if(!($dbnpanxx = mysql_query($qnpanxx, $dbconnect))){
print("MySQL reports: " . mysql_error() . "\n");
exit();
}
if (mysql_num_rows($dbnpanxx) > 0){ //start if
$npanxxcnt = 0;
while($urownpanxx =
mysql_fetch_object($dbnpanxx)){
//output originating npanxx
fputs($npanxxfile,
$urownpanxx->o_npanxx);
//output terminating npanxx
fputs($npanxxfile,
$urownpanxx->t_npanxx);
//output spaces in characters 13-66
for($spaces = 13; $spaces <= 66;
$spaces++){
fputs($npanxxfile, " ");
}
//output "N"
fputs($npanxxfile, "N");
//output spaces in characters 68-86
for($spaces = 68; $spaces <= 86;
$spaces++){
fputs($npanxxfile, " ");
}
//output terminating newline
fputs($npanxxfile, "\n");
$npanxxcnt++;
}// end while
mysql_free_result($dbnpanxx);
}// end if
}// end writing loop
fclose($npanxxfile);
?>
Here are a couple of lines of the output file...(the spaces are
necessary). Each line is 87 bytes long including the newline character.
626677213532 N
626677213533 N
626677213534 N
626677213538 N
626677213542 N
I have STFW, RTFM taken a couple of SWAG's and still cannot come up with
a solution. Is the opened file held in memory and therefore as it gets
larger it approaches the memeory limit of the machine? Any insight would
help...a BIG THANKS IN ADVANCE!
Jay
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php