Take the 2-minute tour ×

I have a PHP script that calls exec() to convert video files using ffmpeg. The script works fine with smaller files, but larger files, usually around 20MB, produce a 500 Internal Server Error after the conversion has run for about 45 seconds.

The max_execution_time is set to 600 seconds (10 minutes) and the max post and upload sizes are set to 1000 MB. The server is Unix based and is not running in safe mode.

Although the issue only happens with larger sizes, I'm not even sure it's a file size issue. The script will pass with a 12.6MB MOV file but will fail with an 11MB MP4 file.

Below is the exec() line from my script:

exec('ffmpeg -y -i '.escapeshellarg($uploadFile).' -vcodec libx264 -ab 128k -ac 2 -b 640k -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -maxrate 10M -bufsize 10M -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 '.$convertFile);


share|improve this question
Long running job should be running on background. Older ffmpeg has bugs, ensure you are running latest version. Try running the same command inside terminal, without php. –  Petr Oct 27 '11 at 14:54
It runs fine in Terminal. The conversion works, even when the internal error is thrown; it simply doesn't call any of the lines after the exec(). I can check the FTP after the error is thrown and there will be a working video file in the directory. –  Scott Heath Oct 27 '11 at 17:51
add comment

1 Answer

I've experienced similar issues with PHP and timeouts using mod_fcgid and Apache. mod_fcgid seems to have an issue with scripts that run a long time, and no matter the amount of changing the timeout values I still couldn't get it to play nice all of the time.

Some options I found to solve this:

  1. Don't use a PHP script - use PHP CLI and a cron job
  2. Don't use mod_fcgid on the site you are using to encode, use a CGI wrapper or even mod_php

I'm editing this as I've found a very useful set of links which have solved my problem:



I added:

<IfModule !mod_fastcgi.c>
    AddHandler fcgid-script fcg fcgi fpl
    IdleScanInterval 10800
    BusyScanInterval 10800
    ZombieScanInterval 60

into my fcgid.conf file and

IPCConnectTimeout 10800
IdleTimeout 10800
ProcessLifeTime 10800
BusyTimeout 10800

into my httpd.conf in the relevant <VirtualHost>, restarted apache and the timeouts have stopped.

share|improve this answer
add comment

Your Answer


