Uhm, Okay,

I get it ... I am loading all at once, will try this out.

Here is what I do:

-- begin code
$network = "IA";
$station = "BJI";
$channel = "BHZ";
$year = 2011;

$top = NULL;

$result = mysql_query('select '.$year.' as year, net, station, loc, channel, start_day, start_time, end_day, end_time from data_'.$year.' where net = "'.$network.'" and station = "'.$station.'" and scal_date BETWEEN "'.$year.'-01-01" AND "'.$year.'-12-31" and channel = "'.$channel.'" ') or die(mysql_error());

echo "Loading $year ... ";
while ($r = mysql_fetch_array($result, MYSQL_ASSOC)) {
        if ($top === NULL)
                $top = new Segments($r, 120);
        unset ($r);
echo "Done\n";

echo "Nothing free: ".memory_get_usage(True)." \n";
echo "SQL free: ".memory_get_usage(True)." \n";
echo "Segments free: ".memory_get_usage(True)." \n";
-- end code

The Segments object is a class with some functionality but, after processing the results of each row it stores two integers (or floats due to the large numbers, number of seconds from epoch * 10000.0 + microseconds).

I will try to implement this chunk mode of fetching the data from sql to see if the php consumption goes down.



On 09/25/2012 02:23 PM, shiplu wrote:
I would like to see how you are reading data from database?

There are many ways to reduce memory usage. Here is a very common way
reduce memory.

instead of

$res = mysql_query("select * from table1 limit 10000000");
while($row = mysql_fetch_assoc($res)){
  /// process row.

Do this,

for($x = 0; $x< 10000000; $x+=100;}
     $res = mysql_query(sprintf("select required_col1,  required_col2,
...  from table1 limit %d, %d",$x, 100));
     while($row = mysql_fetch_assoc($res)){
         /// process row.

Shiplu.Mokadd.im <http://Shiplu.Mokadd.im>
ImgSign.com | A dynamic signature machine
Innovation distinguishes between follower and leader

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to