How to avoid timeouts when importing a WordPress export XML file

WordPress provides a great mechanism for exporting and importing data simply by using Tools > Export or Import. However when used on large datasets, you’re bound to run into timeout issues, especially when that data includes images since it takes time for the importer to grab those images from their source and download them into the destination site.

While most hosting providers (including us on Titanium plans) allow you to adjust the PHP timeout values to increase them to your liking, there are additional timeouts that are not adjustable. These permanent timeouts on shared hosting help ensure that if there are ever any runaway scripts that aren’t being monitored, they will not impact performance for any great length of time. But of course, they can be problematic to deal with when you are monitoring something and want to import data that will take quite some time.

The solution: wp-cli

WP-CLI is a command line method of working with WordPress. Rather than invoking the import command using a URL, you do so when logged in via SSH which bypasses nginx, apache, fastcgi, and php timeouts since it doesn’t use anything but straight-up PHP to run.

This guide is specific to running this on a Plesk server. It is an advanced guide because you must be familiar with connecting to your server via SSH and using the command line to use it.

1] Get your Export File

Download export file from source site by logging in to the WordPress admin then choosing Tools > Export. You can download all content, or just specific content if you wish by selecting the type of content you wish to export.

If you choose specific content (like posts) and there are images in your content, you will not be able to transfer them without also making an export of type “Media”

2] Upload export file in Plesk

  • Login to Plesk
  • Find the domain you wish to import to, then select “Files” to go to the Plesk file manager. You should be looking at the WordPress files like wp-config.php and the wp-content folder.
  • Drag and drop the WordPress XML export file into the file manager to upload it.

You can, of course, also upload via FTP/SFTP if you prefer that method.

3] Set up Environment & Import

Login via SSH and change to the directory you just uploaded the XML file to, then run the following.

Note that you can replace /opt/plesk/php/7.0/bin/php with straight up php if you wish to use your operating system’s stock PHP version. You can also replace it with different Plesk PHP versions simply by swapping out the 7.0 with the version of your choice, like 5.6, 7.1, or 7.2, but you must (of course) have that version installed using the Plesk installer on your server. We have version 7.0 installed from the Plesk installer on all of our servers.

USER=[put your SSH username here]
curl -O
chown $USER:psacln wp-cli.phar
/opt/plesk/php/7.0/bin/php wp-cli.phar --info
sudo -u $USER /opt/plesk/php/7.0/bin/php wp-cli.phar --authors=create import <xml_filename>

If you have multiple XML files (like one for posts and one for media), repeat this for each of them.

If there is any problems during the import (like the process is killed) you can always re-run it. In all cases where I’ve had to do this, the import utility has skipped over existing imported items and resumed where it left off.

That’s it! This guide shows you how to import your WordPress XML exports by using CLI to avoid web server timeouts.

Source for installing wp-cli

Jordan is a computer, security, and network systems expert and a lover of all things web and tech. Jordan consults with project management for software companies. Jordan is a founder and managing partner at Websavers Inc.

Leave a Comment