memory limit exceeded
| From: | Gunjan Kapoor | Date: | Tue, 18 Jul 2000 11:53:12 +0000 |
| Subject: | memory limit exceeded | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-7059@lists.php.net to get a copy of this message | ||
hi,
I'm running the following scripts which retrieve about 20000+ records from
the MySQL database. I'm using PHP4 on Apache (UNIX). However the script
execution completes only once. The second time onwards it gives a "memory
limit of 16 MB exceeded error".
I am using mysql_free_result. so that should not be an issue.B
<?php
//tst_db.php
function start_MYSQL ($host, $user, $passwd, $db)
{
if (!($conn = mysql_pconnect ($host, $user, $passwd)))
{ exit(); }
if (!mysql_select_db ($db, $conn))
{ exit(); }
return $conn;
}
function end_MYSQL ($conn)
{
if (!(mysql_close ($conn)))
{ exit(); }
}
function select_MYSQL ($conn, $stmt)
{
if (!($result = mysql_query ($stmt, $conn)))
{ exit(); }
$rows = array();
for ($i = 0; ($row = mysql_fetch_array($result)); $i++)
{
$rows[$i] = $row;
}
mysql_free_result ($result);
return $rows;
}
?>
<?php
// tst.php
require ("tst_db.php");
$conn = start_MYSQL ("", "gkapoor", "gkapoor",
"eprowess");
$COS = array();
$query = "select entity from kompany";
$rows = select_MYSQL ($conn, $query);
for ($i = 0; $i < count($rows); $i++)
{
$co = $rows[$i]['entity'];
array_push ($COS, $co);
}
$set = 100;
for ($i = 0, $lim = count($COS); $lim > 0; $lim-=$set, $i+=$set)
{
$set = (($lim > $set) ? $set : $lim);
$cos = join (", ", array_slice($COS, $i, $set));
$query = "select kcompany, return from stocks where kcompany
in ($co
s) and date between \"$from\" and \"$to\"";
$rows = select_MYSQL ($conn, $query);
$old_co = ""; $tot_ret = 1;
unset($rows); unset ($cos);
}
unset ($COS);
?>
TIA
Gunjan