Fatal error: Maximum execution time of 30 seconds exceeded

When PHP is processing a file upload and you receive the error message “Fatal error: Maximum execution time of 30 seconds exceeded” it is because the script has timed out. I was working on an application where this was occuring during a file upload. The entire file would be uploaded, then the error would be displayed

Various websites instruct you to call set_time_limit() on the upload page. This overrides the max_execution_time setting which is found in php.ini. Calling this function on my upload page seems to have no effect on my server.  Changing max_execution_time in php.ini to 0 is supposed to be an unlimited timeout. However i was still receiving the error message. It would say “Fatal error: Maximum execution time of 0 seconds exceeded” which does not make any sense to me at all.

I discovered that, in addition to max_execution_time there is an additional setting max_input_time which controls how long a php file can spend processing the request data.  When i set max_input_time to a higher value, the problem goes away. So, it appears that the error message is reporting the wrong configuration variable.

These settings are found in php.ini, however depending on your host you may be able to override them either in your script or in an .htaccess file.   After you update php.ini you may have to restart your https server process to reload the php settings.  (windows servers may need to recycle the application pool).

45 Responses to “Fatal error: Maximum execution time of 30 seconds exceeded”

  1. Olivia September 28, 2007 at 3:17 pm #

    Hi,

    This is really helpful… and I know I’m going to sound very ‘green’ when I say this… but how can I edit the ‘max_execution_time’? I have no idea what ‘php.nin’ is exactly. :(

  2. Jason September 28, 2007 at 4:41 pm #

    Hi Olivia – php.ini is the global configuration file for PHP. Depending whether you are running on your own computer or a shared web host account, you may or not have access to change that file.

    You can read more about it on the php site – http://www.php.net/ini

  3. esra October 15, 2007 at 6:02 pm #

    You might want to take a look at some existing PHP software to see how this is handled. I would recommend downloading a copy of the Joomla 1.1.x release along with the Docman or Repository components. Both allow the uoload and download of large files, especially Docman which is often used to handle the downloading and uploading of large PDF files.

  4. Jason October 15, 2007 at 10:31 pm #

    Hey Esra, Thanks for the Docman tip, I checked that out. Technically, you could still get this same execution error with those components because they still depend on the php ini settings. You can override ini settings in your php code using ini_set, which is what most upload/download components do. However you’ll run into a host once in a while that doesn’t allow it. Most decent hosts do, though.

  5. Naveed Hussain November 7, 2007 at 8:35 am #

    Fatal error: Maximum execution time of 30 seconds exceeded in /var/www/html/squirrelmail-1.4.9a/class/deliver/Deliver_SMTP.class.php on line 198

  6. website designing Pakistan Peshawar March 26, 2008 at 2:39 pm #

    Im also Having this problem,
    i can set it in local php.ini file but from where i will set thise configuration when this is on hosting server because then i have no access to php.ini file

  7. arkmads May 20, 2008 at 1:16 pm #

    this was helpful…really helps me a lot..thanks to you

  8. dieq41 June 7, 2008 at 7:42 am #

    I have change php.ini in C:/Windows like this.. “max_execution_time = 600 ; Maximum execution time of each script, in seconds”, but i still have the problem Fatal error: Maximum execution time of 30 seconds exceeded in C:\AppServ\www\diky\log_dndb\cari_dataesn_vcr.php on line 58.

  9. dieq41 June 7, 2008 at 9:06 am #

    Guys, I have the answer..
    I put the script like this..
    //set time limit 180 seconds

    in my script, it can work to run query more than 30 seconds.and the result..
    “Time to query : 43.066 seconds.”..
    Thx to all..

  10. shanti August 11, 2008 at 2:30 am #

    hello friends…

    i got the same error on my web page…
    but is there any coding tips to load our page fastly,when we are using mysql,php,html.

  11. Gulrez September 26, 2008 at 7:07 am #

    hello,

    I have found only this solution for this error
    “i set max_input_time to a higher value in my php.ini file” but if i m using only few php pages then how i can fix this problem by the coading.

    Plz Reply

  12. Plaska December 26, 2008 at 12:09 am #

    Thank you so much for posting this solution.

  13. arafat March 29, 2009 at 4:08 am #

    simple follow this instruction: (why people always give hard instruction to others?)

    1) Open your notepad. and paste this code:

    max_execution_time = 120
    max_input_time = 120

    2) Save it as php.ini

    3) Upload the file using FTP/Cpanel and Put in /administrator folder (joomla direcory)

    4) DONE! Now you can install any files without having the message Fatal error: Maximum execution time of 30 seconds exceeded bla bla bla bla..

    • Jason March 31, 2009 at 2:06 am #

      thanks arafat. sometimes when I have a technical problem, I’m not really interested in the details and i just want my problem fixed. I understand what you are saying that instructions are often overly complicated. unfortunately it is not usually possible to give exact instructions unless everybody is using the exact same server setup. my instructions are purposely “generic” so that people reading will understand the problem and then they can fix it on their machine – even though their setup is probably slightly different than mine.

      i’m sure your instructions work perfectly on your host, but that is not a standard location for php.ini – I’m guessing it is specific to CPanel or Joomla or even your particular host. also, i would strongly advice against overwriting your existing php.ini file because there are many more settings in that file and overwriting the file would blow away any existing php configuration settings. it would be better to open the file and edit only the lines that are relevant.

    • Usman Akbar June 28, 2011 at 1:12 am #

      you can also fix this problem by adding following code:

      set_time_limit(60);
      it is built in function.

  14. umar May 12, 2009 at 11:06 am #

    hi,
    i m also facing same problem
    Fatal error: Maximum execution time of 30 seconds exceeded in c:\apache\htdocs\ims\process.php on line 42

    and at line 42 i have this statement
    while(!feof($fptr_id))
    i read all your comments and other suggestions but i am not able to find “php.ini”,max_execution_time,max_input_time,etc
    thanks ..

  15. ram June 4, 2009 at 6:20 am #

    excellent the parameters retrned were really misleading, but this directive has solved the problem immediately

  16. Umar August 9, 2009 at 5:56 am #

    Great Thans alot

    I changed both
    max_execution_time = 600;
    max_input_time = 600;
    I have 11 MB file to download, I calculated the time for downloading it, and changed accordingly. But if the file size differs may be 100 MB, 200 MB, 750 MB then how much value need to place in
    max_execution_time;
    max_input_time
    ?

    How I can fast up the downloading speed?
    Do you have any efficient PHP downloading script? If so please send me.

    Once again Thanks for you help

    • Jason August 11, 2009 at 3:49 pm #

      Hey Umar, the execution time is affected by the connection speed of your visitor, so there is no fixed number. You could probably calculate it based on a reasonable connection speed and then set your server limits with a conservative value.

  17. Sukhwinder January 27, 2010 at 9:53 am #

    i Have problem same like above but the diff is that i am trying to deleting 987900 from the database but in one time i can delete only 780 or 785. how can i delete the whole record

  18. Jason February 3, 2010 at 1:42 pm #

    @Sukhwinder
    The problem is not really with deleting, but just the script is taking too long to run. You either have to bump up the PHP limits or think of another way to accomplish that same thing. Maybe a queue or use ajax to do it in batches?

  19. dieq41 April 8, 2010 at 1:58 am #

    you can add this script in your php code..

    set_time_limit(180);//set limit to running maks 180 seconds

  20. joren April 21, 2010 at 4:55 pm #

    hi all, i had a similar problem. it was resolved by the follwing setting:

    max_execution_time = 180
    max_input_time = 180

    Make sure that the execution time and input time is either the same or the input time should be double the execution time and not the other way around ie:

    max_execution_time = 60
    max_input_time = 120

    I hope you finds this helpful. it really helped me :0

  21. freddo July 21, 2010 at 4:05 pm #

    thx so much for information…

  22. Neelesh December 4, 2010 at 2:47 am #

    You can also use this set_time_limit(0),Pass the zero,it will run until ur job not done.

  23. batz March 1, 2011 at 3:01 am #

    Hi, thx for that info, i have the same problem..

  24. manab ganguly March 9, 2011 at 12:25 pm #

    when i install jevent in joomla then this error show me

    Fatal error: Maximum execution time of 30 seconds exceeded in ………………

    what i am doing now

    my WampServer Version 2.0

    joomla 1.5

    jevent 1.4

  25. Raghibsuleman April 12, 2011 at 12:46 am #

    Thank you so much its very helpful…

  26. Jeff August 3, 2011 at 10:16 pm #

    I have this problem Fatal error: Maximum execution time of 90 seconds exceeded in \\boswinfs04\home\users\web\b2844\whl.kellc\shopping\catalog\model\tool\image.php on line 4
    , and I looked at php.ini setting below.

    magic_quotes_gpc = Off;
    register_globals = Off;
    default_charset = UTF-8;
    memory_limit = 64M;
    max_execution_time = 18000;
    upload_max_filesize = 999M;
    safe_mode = Off;
    mysql.connect_timeout = 20;
    session.use_cookies = On;
    session.use_trans_sid = Off;
    session.gc_maxlifetime = 12000000;
    allow_url_fopen = on;

    I am little confused but it seems I need to add like this below.

    magic_quotes_gpc = Off;
    register_globals = Off;
    default_charset = UTF-8;
    memory_limit = 64M;
    max_execution_time = 18000;
    max_input_time = 18000;
    upload_max_filesize = 999M;
    safe_mode = Off;
    mysql.connect_timeout = 20;
    session.use_cookies = On;
    session.use_trans_sid = Off;
    session.gc_maxlifetime = 12000000;
    allow_url_fopen = on;

    So is 18000 is better or should be less? I saw it Nelesh mentioned set_time_limit(0), sorry I am still learning on this part.

  27. juanma August 29, 2011 at 7:06 pm #

    @joren you are the best!

    I resolved my problem

  28. Liam September 23, 2011 at 6:01 am #

    Worked at treat, thank you.

  29. Tom October 15, 2011 at 7:51 pm #

    Brilliant fix. Thank you!.

  30. Ubuntoo December 7, 2011 at 4:45 pm #

    Interesting post.
    For a couple of solutions of the original problem (exceeding execution time), use set_time_limit() function or change php.ini configuration file.
    You can find out how here: PHP time limit

  31. pankaj January 19, 2012 at 11:06 pm #

    Hi i have taken windows shared hosting and when i added plugin it says Fatal error: Maximum execution time of 30 seconds exceeded.As i contact to hosting provider they said they will not increase execution time more that 30 sec.so please tell me to add some code in wordpress config so i can proceed.
    thanks

    • Jason January 20, 2012 at 4:31 am #

      If the host doesn’t allow you to override the execution time setting then your only choice is to get a new host. But, on shared hosting they will almost always set certain limits to prevent one single customer from hogging all the server resources.

  32. Suteki February 17, 2012 at 8:40 am #

    work like charm.. thanks mate

  33. Jatinder March 2, 2012 at 8:34 am #

    If you are running xampp then in phpMyAdmin folder open (config.default.php) file
    and set variable ($cfg['ExecTimeLimit']) value to 0.

    It runs for me in xampp.

    whether you export/import db or executing query via php

  34. lito May 10, 2012 at 4:03 am #

    help me guys..fatal error:maximum execution time of exceeded 0f 30 sec execution

  35. Nouman Abbas June 15, 2012 at 10:56 am #

    Thanks for the great help dear. I am facing it on wordpress 3.4 upgrade.

  36. Lucky August 6, 2012 at 5:40 am #

    Thanks for this code.I am making a small fetching script & most of the time it is showing fatal error.Finally,I found a solution.

  37. ksa December 21, 2012 at 1:12 am #

    I had the same problem.

    Thanks for help

  38. Yosué September 3, 2013 at 11:54 am #

    Thanks a lot for this post, solved my problem :)

  39. Martin November 15, 2013 at 1:28 pm #

    Hi,
    what if the other side, the webservice where the page is conecting to is down?
    The adjustment won’t help much.
    How can you handle that message and print something more elegant??

    Best Regards

    • Jason November 15, 2013 at 1:49 pm #

      If you’re page is timing out due to a third-party API then you would want to set some type of timeout in your code when you make the call, then you could handle it in some other way – showing a more friendly message for example

Leave a Reply

Please leave these two fields as-is: