How to limit max downloads in apache?

Stouf

Registered
Oct 28, 2018
4
0
1
Mara
cPanel Access Level
Root Administrator
How do you limit the max number of simultaneous downloads at same time and display a too many users error when that limit has been reached in apache?
 

rpvw

Well-Known Member
Jul 18, 2013
1,101
465
113
UK
cPanel Access Level
Root Administrator
There are probably many ways of achieving this ...... here is one way I would explore if I were trying to solve the problem.....

Use PHP to create session files for each started download, that were then stored or enumerated in a database (MySQL or SQLite - whatever rocks your world), and counted before allowing a new session (file download) to be started - if the number of sessions is over the set limit -> display "too many users" error.

Don't forget to delete the session entry when the download finishes.

Use your favourite search engine to look for "PHP how to count downloads" for ideas and code examples.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,219
463
Hello @Stouf,

Let us know how it turns out.

Thanks!
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,219
463
Hello @Stouf,

I don't have a specific PHP script to recommend, but there are some limits you can configure for Apache in WHM >> Apache Configuration >> Global Configuration. For instance, Max Request Workers is a value you could adjust:

This directive sets the limit on the number of simultaneous requests that will be served. This interface allows up to the value of the ServerLimit setting. This used to be called 'MaxClients' prior to Apache 2.4.
Thank you.