K. Tsang wrote:PHP has threads too similar to java. The PHP library for multi-threading is "pthreads" containing classes like Thread, Worker, Threaded etc
Have a look at the pthreads library
By the way I didn't use such library before.
K. Tsang wrote:For the query optimization, look into adding indexes. But first try to get an execution plan of the sql from the database using the "explain" command.
What database are you using? If MySQL have a look at here for more info.
K. Tsang wrote:Going back to the very beginning. You mentioned you are joining 3-4 tables. 50K records becomes 150K? How are you joining the tables? left join, inner join
Since you gone over the explain optimization stuff, I suppose you have taken action with the suggestions from the execution plan.
You plan to export the data but doing "all" records (eg 50K+) in one go is indeed disk I/O intensive. Doing this in chunks would probably improve the performance.
Furthermore, you should know the data size of each record (export a multiple factor) should again improve.
Lastly partitioning table by date or something may be possible.
Your issue is more of a database issue rather than PHP.