# Can a server handle simultaneous shell commands?

I'm writing a very simple browser based MP3 player in PHP. Part of this project requires that every MP3 file is converted to a WAV file. There's a function in PHP called shell_exec that allows you to execute a command via the shell. For my project, whenever someone uploads a song to their account, the following command would be executed:

shell_exec('ffmpeg -i inputSong.mp3 outputSong.wav')


So let's say there are 10 different people who finish uploading a song at the same exact time. Does the Linux server execute 10 shell commands simultaneously or does it only do one at a time?

If a server can handle multiple shell commands simultaneously, would the server be able to handle converting 10 different songs at the same time or does it only do one at a time?

• How is this ubuntu related? Doesn't it belong on serverfault or unix? – bitmask Aug 28 '11 at 16:28
• Be very careful with accepting the input filename from the user. Someone might specially craft a filename that mimics some command, and that you would execute, and you would essentially be hacked. – Rory Aug 29 '11 at 16:22

If you are doing it via PHP (or any other language that has access to shell commands) they will be done separately, which means that they will be done simultaneous if by chance the 10 users use the PHP script at the same time. Each PHP call through shell_exec will be done independent of the others. I myself have a shell_exec script which shows some information to my users for certain images and this is done independently from other PHP executed scripts through shell_exec.

There is a limit to how many simultaneous users PHP can handle, but it depends on your web server, PHP configuration file and MySQL if you are using it. I know the number is greater than 100 at the same time.

When using CPU intensive commands, for example converting videos, the effective use of the commands would then depend on how much RAM you have and how much CPU power you have. For someone with 64 MB RAM and a 80486 it would go bad to try to convert two videos and 10 songs. That would overload the system. For someone with a Core 2 Duo server and 4 GB RAM I think converting several songs would be a piece of cake.

So basically, yes, Linux can handle multiple simultaneous shell commands, specially from PHP, but the overall performance would depend on the resources of the server (CPU, RAM, hard disk drive, etc.)

If you were to support a large number of users you would have to investigate an alternative method of handling the conversion process.

For example you would likely setup a job scheduling system such that you post requests to the system to convert a file and poll the system for completion status. The scheduling system would take tasks from a queue and say perform up to four file conversions at a time.

This question might be of interest:

https://stackoverflow.com/q/265073/175849

• Another great answer, thank you steve-o – user784637 Aug 29 '11 at 1:37