Does PHP wait for the exec command to complete before continuing on to the next php commands?
If PHP doesn’t wait, would there be a way of forcing it to wait…eg, create a while loop that checked the fileszie of 00000001.jpg etc, and the while loop wouldn’t stop until the filesize has stopped increasing in size (ie. when the image had completely generated) or, when the filesize is > 0 (depending if the output is written incrementally, or all at once)?
I’m wanting to prevent > 5 multiple ffmpeg instances running at the same time, as this script is in a batch FLV uploader, so 400 vids could be uploaded at once, and I don’t wont more than 5 (the number of thumbs per vid) ffmpeg to be happening at once (or is 5 too many?, if so 1 a time would be fine). Just wanting to prevent the possibility of 100s of ffmpeg instances running.
When allowing user-supplied data to be passed to this function, use escapeshellarg() or escapeshellcmd() to ensure that users cannot trick the system into executing arbitrary commands.
Note: If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.
Yes, by default exec() won’t return until the program finishes. Now, it’s definately possible that some programs might in turn spawn thier own children so to speak, which will do the work, so the parent program can just die off immediately. This would be a case where exec() could possibly return before the operation was actually done(some scenarios), but you probably won’t encounter too many programs like this. In a case like this, you would need to do a loop like you suggested where you just keep sleeping and doing a manual check for completion.