Check if the upload takes too much time and in case notify the user?

I'm try do detect PHP script execution timeout when user uploads a lot of file with a slow Internet connection: i should only warn the user about the timeout.

I'm using register_shutdown_function() along with connection_status() in my upload.php and inside on_shutdown() i create a $timeout flag to use in complete.php to detect timeout.

The problem is that results are completely wrong: i've got a timeout fatal error (it's ok), a require fatal error (at function require($require), as if $require was empty) and complete.php is not shown.

Too bad, i can't figure how where i'm wrong. This is (short version of) upload.php script:

   $require = 'complete.php'; // Complete page

   sleep(50); // fake timeout for testing

   // Do stuff, save files, insert into database...

   // This always invoked
   function on_shutdown()
      global $require;

      $timeout = connection_status() == 2;

... and this is complete.php:

<!DOCTYPE html>
        <title>Upload complete</title>
        <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
        <?php if ($timeout) { ?><!-- is timeout? -->
            <p>Upload process took too much time, results are unpredictable.</p>
        <?php } ?>


register_shutdown_function('on_shutdown'); Will run only after the script is executed.

"Registers a callback to be executed after script execution finishes or exit() is called." -

instead of trying with timeout, you can check the values of maximum execution time and assign it to 0 for long execution, but security wise 0 is not recommented

$maxExeTime = ini_get('max_execution_time'); //this will get maxumum excetion time for PHP script in seconds
echo $maxExeTime;

and also you can check below global variable also

$postMs = ini_get('post_max_size'); //this will get maxumum size of data to be accepted in $_POST
$upMaxFiles = ini_get('upload_max_filesize'); //this will get maxumum allowed file size for file upload
$noFilesUp = ini_get('max_file_uploads'); //this will get number of files to be load on    single request

Need Your Help

How to make my app singleton application?

c# .net windows-applications

I have a application but currently it is not a singleton application.

Adding new facts to a file in Prolog

prolog sicstus-prolog

I have a problem in Prolog regarding adding new facts to the file ''. Every time I get facts I save them and I use

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.