Tweaking php For Maximum Execution Time For Scripts

I‘ve been trying to migrate my webblogs using WordPress inbuilt import facility. I’ve exported current blog as a xml file and downloaded to my desktop. Next I navigated to my new blog’s admin area and clicked on Manage > Import. However import failed after importing 50-60% posts only.

I went through Apache and PHP log files and I realized that the script was timed out. How do I fix this problem under Linux / UNIX?

PHP by default places resource limits on all php scripts using the following three directives:

=> max_execution_time : Maximum execution time of each script, in seconds (default 30 seconds)

=> max_input_time : Maximum amount of time each script may spend parsing request data (60 seconds)

=> memory_limit : Maximum amount of memory a script may consume (default 8MB)

Your php script was timed out because of resource limits. All you need to do is setup a new resource limits so that the script will get executed:

Open /etc/php.ini (or /etc/php5/php.ini) file:
# vi /etc/php.ini
Locate and setup new resource limits as follows:

# 600 seconds
max_execution_time = 600

# 120 seconds
max_input_time = 120

# 64 MB
memory_limit = 64M  

Restart Apache or lighttpd web server:
# /etc/init.d/httpd restart
# /etc/init.d/lighttpd restart

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 3 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
3 comments… add one
  • DaiLaughing Feb 2, 2008 @ 14:11

    php.ini was in /etc/php5/apache2 for me and the apache2 restart is done by:

    /etc/init.d/apache restart

    which might help others with Ubuntu. Thanks for the tip.

  • AJi Prabowo Nov 10, 2010 @ 13:08

    I surely find this article is useful to me. The script does work!!


  • Andrejs Jan 3, 2011 @ 17:09

    My php script always stopped after 10-14 hours :(

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum