I have a problem with exporting large amount of data to csv file using php.
Information:
- Need to export 700000 list of addresses from database table(address).
- Server timed out or lacking memory
- project I'm working on working with multiple servers
My solution(what have i tried)
Get data part by part(from database) process this data(fputcsv
) write this part to the temporary file - and send information to user via Ajax
(show him the amount of processed Percentage). After last part of data has been processed just give user link to download this file. All is fine i have did this and this solution works for me - on my local enviroment, but
the problem is - project I'm working on working with multiple servers
so I ran into a problem that temporary file can be stored on different servers.
For Example:
I have 3 servers: Server1
, Server2
and Server3
.
First time i read data from db with limit 0 50000
- process it and save it to File.csv
on Server1
, next iteration limit 50000, 50000
can be saved on another server Server2
- this is the problem.
So my question is:
Where i can store my processed temporary csv data, or maybe i am missing something, i am stuck here, looking for advice. Every suggestion or solution will be appreciated! Thanks.
UPDATE
PROBLEM IS SOLVED
Later i will post my solution