Re: memory limit exceeded
| From: | Carroll Barrett | Date: | Tue, 18 Jul 2000 15:38:54 +0000 |
| Subject: | Re: memory limit exceeded | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-7086@lists.php.net to get a copy of this message | ||
Gunjan,
If you are calling select_MYSQL() like this
$data=select_MYSQL(($conn, $stmt);
then $data is an array of 20000+ entries. If you don't unset
$data before your second call to select_MYSQL(), this memory will
no longer be available.
I hope this explanation is clear enough; if not, you can email me
privately.
Regards,
Carroll Barrett
-----Original Message-----
From: Gunjan Kapoor <gkapoor@cmie.com>
To: php-general@lists.php.net <php-general@lists.php.net>
Date: Tuesday, July 18, 2000 7:13 AM
Subject: [PHP] memory limit exceeded
>
>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
>
>
>
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
>For additional commands, e-mail: php-general-help@lists.php.net
>To contact the list administrators, e-mail:
php-list-admin@lists.php.net
>