Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

omsutariya's avatar

Can not download multiple excel sheets in one request.

I am using this package: laravel-excel

the code to generate the excel file: return Excel::download(new Students_Data_Chart_Export($students, $heading),'Students Data .xlsx');

where $students is the data for excel sheet and $heading is the heading of excel sheet.

While downloading, if the excel contains 1800 students data to calculate, the time to process exceeds 1 minute, in which case the Cloudflare gives error: A time out occurred, because server is calculating for 1 minute and is not responding.

I am thinking to split that 1800 students based on class, because there are 300 students in 1 class. So, if I can download 6 excels per request, there will be 1 excel downloaded in 15 sec. for 1800, it will take 1 minute + so the error is occurring, so this class wise excel method will download 6 excel files. Overall time will take 1 minute+, but while the server is responding in 15 sec, Cloudflare won't give an error.

Problem is, I can not download multiple excel sheets in 1 request. I can not write:

Excel::download(new Students_Data_Chart_Export($students2, $heading),'Students Data Grade 1 .xlsx');

return Excel::download(new Students_Data_Chart_Export($students2, $heading),'Students Data Grade 2 .xlsx');

etc...

where $students1 is students from grade 1 and $students2 is students from grade 2. the only statement that excutes is statement 2 i.e. statement with return keyword.

I need help with this problem.

0 likes
15 replies
Tray2's avatar

I would schedule the creation of the file, generate it, and then send a notification to the user when it's ready. However, 60 seconds to generate a file is way too long, I would analyze the queries to see what takes such a long time, and then add the proper indexes, because it's very likely the database queries that have bad performance.

1 like
omsutariya's avatar

@Tray2 Thankyou for the reply. the problem is, the excel file is containing all students data, 20 headings per student. This file has every data containing student. I work in a startup so the servers are not that powerful. Is there any method to download multiple files per request? Consider that the queries are the best that I can do.

Tray2's avatar

@omsutariya I suggest that you take each of the SQL queries that you run in the method, and put explain in front of them, and look for full table scans and such.

EXPLAIN SELECT * FROM table_one WHERE name = 'Aaron';

If it tells you that it uses full table scan, then you should probably create and index for the name column.

Also make sure that all your foreign keys are properly formed.

Give this one a read as well https://tray2.se/posts/properly-formed-foreign-keys-are-your-best-friends

1 like
Snapey's avatar

that is extremely slow for just 1800 students.

Make sure first that your queries are optimised and indexed properly. If you have already done that, consider generating the export in advance. No user should wait a minute for an export.

Sorry @tray2 , I should have read your post first which I just echoed.

2 likes
omsutariya's avatar

@Snapey Thankyou for the reply. the problem is, the excel file is containing all students data, 20 headings per student. This file has every data containing student. I work in a startup so the servers are not that powerful. Is there any method to download multiple files per request? Consider that the queries are the best that I can do.

Snapey's avatar

@omsutariya no need to reply same to both.

So what do you do with the data that takes so much time?

1800 rows of 20 columns would export in less than 1 second

omsutariya's avatar

@Snapey all students data like name, email, gender, certificates, no. of logins, different modules viewed in our platform + which sub-modules they viewed (there are total 12 modules), this calculation is happening in the download request. so, the downloading time cannot be reduced. The only solution according to me is to make server answer in 1 minute by downloading excel file. If I can not download all students from a school, I can download students per grade, so it will take 15 sec per grade, So I am seeking this kind of solution.

Snapey's avatar
Snapey
Best Answer
Level 122

@omsutariya sounds like you don't actually want to consider alternative solutions.

What you want to do breaks http protocol. The browser issues a request, for which it expects a single response. You cant change the way browsers work.

You would need to get the client to request students per grade as separate requests.

MohamedTammam's avatar

@Snapey Yes, I just wanted to share the way on how to download multiple files with the same request.

Snapey's avatar

The simplest solution I can think of is to reply to the user immediately and tell them the spreadsheet is in the mail.

Create a queued job that creates the excel and mails it to the user a couple of minutes later.

You may well find that they just come back to you and say this is great, can you send it everyday to save me logging in !

1 like
krisi_gjika's avatar

your solution is not very scalable, even if now it takes 15 sec per grade. what if in the future the grade increases the number of students and you are in the same situation again? Also as a user if I request one thing, I expect to get one thing back, not have to cross check 6 excels to do what I want.

All you need to do is queue the process as a job and respond imediately to the user saying their export is queued. Than either send the download link via an email or create an exports page for the user where they can see the exports in progress and download the finished ones.

1 like

Please or to participate in this conversation.