2

I would like to know a number of simultaneous file uploads in the very moment. E.g. If the number exceeds my limit, I would display a message to the user with apology to try later.

Is there a way how to get the number of currently running uploads in PHP ?

Thank you for your help...

Frodik
  • 14,986
  • 23
  • 90
  • 141
  • You mean how many POST requests are currently running that contain a file upload, across the whole server? Interesting question. – deceze May 06 '12 at 07:06
  • 1
    What kind of limit could that exceed? PHP is not really involved until the upload has finished. If the web server itself can handle several parallel uploads, there should be little reason to limit it... – deceze May 06 '12 at 07:13
  • @deceze You are actually right. I would like to prevent simple DOS attack from bad users that would try to upload big files in one moment. I know it's not bulletproof, but it would save me some pain. PHP must be involved in some way, because I can get upload status of upload running (using APC). – Frodik May 06 '12 at 07:20
  • Maybe this can be configured by the web server itself? – Surreal Dreams May 06 '12 at 07:33
  • Yeah, trying to prevent a (D)DoS in PHP is difficult at best. That's rather a job for the web server itself. – deceze May 06 '12 at 07:34
  • Please, if you can, post an answer either with solution or saying it is impossible with some references. Thank you for you comments and help. – Frodik May 06 '12 at 07:38

1 Answers1

0

For this needs you better use some web-server module. For apache there is mod_qos. One of it's features is Limit the maximum number of concurrent requests to a location/resource (URL) or virtual host - just asyou need. It also can do much more even limit the bandwidth. Info about module is here.

s.webbandit
  • 16,332
  • 16
  • 58
  • 82
  • Thanks for answer, mod_qos looks promising. But am I able to handle the denied request by PHP so I can display polite message to an user ? – Frodik May 06 '12 at 07:56
  • 2
    In `mod_qos` there is `QS_ErrorPage ` config option which states for `error page to be returned when a request is denied`. So you can send denied users to location you like and display them anything you want! – s.webbandit May 06 '12 at 08:04