I've a PHP script that it's being called with a cron job in my server to run uploaded video conversions. It works fine for some videos, but when the video is a bit larger (21MB for example) I get a 500 Internal Server Error
and no other output.
I think that it's possible that this problem was due to timeouts so I've added set_time_limit(9000)
and also ini_set('max_execution_time', 9000)
to prevent this, but this does not solve anything.
I execute ffmpeg using:
$cmdOut = shell_exec ('ffmpeg -y -i [....] 2>&1'); // [....] is the rest of the command, it works fine with other videos, so i assume that it works ok.
echo print_r($cmdOut);
However there is no output, and the following lines are not being executed, so after the shell_exec
t开发者_运维问答he script is aborted.
Looking at the apache error_log I can see this line:
[Wed Jan 12 00:12:46 2011] [error] [client xx.xxx.xxx.xxx] Premature end of script headers: index.php
But there are no other clues. Can anyone help me?
For testing purposes i've created this PHP script:
<?php
set_time_limit(300);
sleep(120);
echo "SLEEP OUT";
?>
This script causes a "500 Internal Server Error" when i call it from my web browser, so i suppose that set_time_limit is not working. If i put sleep(30) it works and it returns the text SLEEP OUT. So the question is, how can i avoid the timeout error to execute a PHP script that is taking 5 or 10 minutes to complete??
NOTE: Server is CentOS running apache and php as FastCGI module.
Finally i've solved this on my own. I've developed a workaround to bypass the timeout limitation in php. My solution is to execute the php script using the php-cli command with a scheduled cron job. This way i don't have the time limit when executing my script and it works nicely.
Thanks to all, specially to Phoenix for their time and ideas about this issue.
Do you really need the console output for anything? I ran into a similar issue once, even though I modified the primary php.ini itself to extend the execution time limit, it would still drop randomly when doing ffmpeg through exec. Wound up having to > /dev/null &
it to stop it from dropping execution, then it worked fine regardless of what was thrown at it.
精彩评论