php.htaccessscriptingphp-ini

Increase max execution time for php


I have added set_time_limit(0); function to increase execution time but its executing only 2-3 minutes maximum.

error_reporting(E_ALL);
error_reporting(1);
set_time_limit(0);

I want to search links from a site which is taking a long time.


Solution

  • PHP file (for example, my_lengthy_script.php)

    ini_set('max_execution_time', 300); //300 seconds = 5 minutes
    

    .htaccess file

    <IfModule mod_php5.c>
    php_value max_execution_time 300
    </IfModule>
    

    More configuration options

    <IfModule mod_php5.c>
    php_value post_max_size 5M
    php_value upload_max_filesize 5M
    php_value memory_limit 128M
    php_value max_execution_time 300
    php_value max_input_time 300
    php_value session.gc_maxlifetime 1200
    </IfModule>
    

    If wordpress, set this in the config.php file,

    define('WP_MEMORY_LIMIT', '128M');
    

    If drupal, sites/default/settings.php

    ini_set('memory_limit', '128M');
    

    If you are using other frameworks,

    ini_set('memory_limit', '128M');
    

    You can increase memory as gigabyte.

    ini_set('memory_limit', '3G'); // 3 Gigabytes
    

    259200 means:-

    ( 259200/(60x60 minutes) ) / 24 hours ===> 3 Days
    

    More details on my blog