I have an upload system ready, however I might be facing a very high load that may bring down our servers. The hosting provider limits the instances of a PHP script running at the same time to about 30. However, while people are uploading they often take longer than expected to finish the script and other people are given an “Internal Server Error” until a spot frees up.
My specific question is, is there a way to limit the number of people running the script at the same time? For example, a queueing system where only 29 people are uploading at the same time (server stays up) and other people can only start uploading when spots free up. How would this be possible?
Save a value (ideally in Memcache, but MySQL works fine too) that says how many people are uploading. It starts at zero, then when someone starts uploading you increment it before starting to process the upload. When the upload has finished, decrement the counter again.
If the counter is above your threshold, stop people from accessing the uploader or give a friendly error message.
Alternatively, find a host with better systems. I hope this doesn’t count as advertising, but the host I use provides much, MUCH better systems, and almost certainly cheaper than whatever you’re paying your current host.