multithreading - PHP PDO SQL MutliThreading Possible? -
i send full flat (edi) file oxford everyday. query database, array of results, , use data array make csv file out of it
$sql = "select * master_table"; $sth = $apex->prepare($sql); $sth->execute(); $result = $sth->fetchall(pdo::fetch_assoc); //this fatal error due out of memory $csv = new csv(); $csv->makecsv($result);
the $result contain array of millions of records make csv.
the main problem i'm having here lack of memory , time. if "break up" sql query this:
$years = [2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011]; //etc foreach ($years year) { $sql = "select * master_table year = $year"; $sth = $apex->prepare($sql); $sth->execute(); $result = $sth->fetchall(pdo::fetch_assoc); $csv = new csv(); $csv->makecsv($result); unset($result); }
this works takes extremely long time due php not being unable execute foreach loop simultaneously. there option in pdo can execute multithreaded queries?
thanks
even if select data faster multiple threads (which can't probably), couldn't write csv faster whatever ... threading doesn't make sense here.
the best solution select outfile
, bypassing php in creation of csv altogether.
Comments
Post a Comment