0

I am trying to download some big videos from dropbox and then upload them again to another server. This works pretty well with small files. However when the files are getting bigger, I keep getting 500er errors. I was trying to catch them via register_shutdown_function (see How do I catch a PHP Fatal Error for more details) but apparently the handler gets never called (I dont get any emails whatsoever). Is there something I am doing wrong here?

// error handler
function fatal_handler() {
    $error = error_get_last();
    if( $error !== NULL) {
        $errno   = $error["type"];
        $errfile = $error["file"];
        $errline = $error["line"];
        $errstr  = $error["message"];
        error_mail(format_error( $errno, $errstr, $errfile, $errline));
    }
}

function format_error( $errno, $errstr, $errfile, $errline ) {
    $trace = print_r( debug_backtrace( false ), true );
    // some beautiful error output with content being the container
    return $content;
}

function error_mail($msg) {
    mail("email@example.org", "Error", $msg);
}

register_shutdown_function('fatal_handler');
error_reporting(E_ALL);
Community
  • 1
  • 1
Jan
  • 42,290
  • 8
  • 54
  • 79
  • No, error 500 means the PHP runtime is terminated, and the shutdown handler never got called either. Research details on the actual cause in the webservers/vhost/fcgi `error.log`. – mario Jun 10 '15 at 20:44
  • 1
    Sounds like you're cramming your downloads into memory, which is either triggering [oom-killer](http://en.wikipedia.org/wiki/Out_of_memory) or possibly another process your host is running to manage memory. If the PHP process is killed externally the execution is halted immediately and the handler is never called. Check your logs, oom-killer logs to `/var/log/messages`. – Sammitch Jun 10 '15 at 20:45
  • How long do these transfers take, and is PHP running as a CGI (php-fpm, fastcgi)? You could be experiencing a timeout between the web server and PHP (often this is set to 5 minutes). When PHP doesn't respond within that timeout period, the webserver terminates the request which results in a 500 error. – drew010 Jun 10 '15 at 21:00
  • @Sammitch: This is a very good hint. Is there a list of memory consuming functions in php somewhere? And am I able to check how much memory I am currently using? – Jan Jun 11 '15 at 20:30
  • 1
    http://php.net/manual/en/function.memory-get-usage.php – Sammitch Jun 11 '15 at 20:37

0 Answers0