tokenage tokenage - 2 years ago 448
PHP Question

Wordpress importer error: max execution time 60 seconds

I am trying to import a Wordpress theme unit test xml with default wordpress importer plugin. I get following error:

Fatal error: Maximum execution time of 60 seconds exceeded in E:\XAMPP\htdocs\wp\wp-includes\wp-db.php

This is a basic Wordpress 4.5.1 installation with no additional plugins or themes, except wordpress importer v 0.6.1, on my local XAMPP server, execution time limit is set to 6000 in php.ini and I can see this preset in xampp's php_info.
I've already tried adding set_time_limit(6000) in wp-config.php and wp-db.php with the same ugly error as result.

Any ideas why is this happening and how can it be helped?

Answer Source

I found the precise reason why this error happens, so I'll try to provide the answer to my own question.

There is a function called wp_get_http in wp-includes/deprecated.php, which is still used by the wordpress importer plugin (inside wordpress-importer.php source file). Inside this function set_time_limit(60) is called, it is the one of exactly two calls to this function with parameter 60 in all the wordpress source code, so this is the place that limits importer execution time to 60 seconds.

wp_get_http is called by importer plugin rather late in the execution flow, so it overrides any other possible set_time_limit() calls in wp-config.php, and cannot be corrected by modifications in php.ini, which by their own may happen to be not allowed by hosting provider.

The quick solution to this, which worked for me, is to modify the set_time_limit call inside wp_get_http() in wp-includes/deprecated.php, like this:

set_time_limit(1200); // Limit to 20 minutes

It gives the wordpress importer 20 minutes to fetch all the remote files it may require during import. This may be not the safest solution, but it worked for me.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download