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, as well as media files that take time to import, you’re bound to run into timeout issues.

Obtaining an XML export from the source

If you’re exporting from another self-hosted WordPress site, you can learn how to obtain your XML export file from the source site here. 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”

How to safely import the XML file at the destination

When importing that file on the destination site under Tools > Import, there are three ways to ensure it imports smoothly:

  1. Learn how to adjust your PHP timeout values temporarily so that you can avoid Gateway Timeout errors, then head to Tools > Import and import the file. Do not forget to set the timeouts back to their original values post-import to avoid performance issues on the site.
  2. Use the WP All Import plugin – it batches the data import so that timeouts are not likely to be reached (this is what the built in WordPress import function should do but doesn’t).
  3. Use the wp-cli utility via an SSH connection to avoid front-end timeouts. Server timeouts are only configured through the web server configuration, and so are not present when importing via command line with wp-cli.

Note regarding Option 1: it can be tricky to estimate how long you need to set the timeout for. If you have more than, say, 100-200 media files in WordPress, it’s recommended to use one of the other two options.

Options 1 and 2 are simpler, while Option 3 (wp-cli) is more robust, but more technical knowledge is required to use it. If you’d like to give wp-cli a try, read on!

Using wp-cli to ensure a reliable import

WP-CLI is a command line method of working with WordPress. Rather than importing using the WordPress admin GUI, 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 following steps are 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. Learn how to install and use WP-CLI on a Plesk server
  2. Upload the file using either SFTP or Plesk File Manager (it’s simplest to upload the file to the domain’s web root folder. How to find the web root is described in both of those guides).
  3. Run the import command: php wp-cli.phar import [my_filename].xml --authors=create

If you have multiple XML files (like one for posts and one for media), repeat the import command 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.

About Jordan Schelew

Jordan has been working with computers, security, and network systems since the 90s and is a managing partner at Websavers Inc. As a founder of the company, he's been in the web tech space for over 15 years.


  1. A on March 11, 2023 at 12:21 am

    i love you!

  2. Rafael Alfaro on October 8, 2018 at 4:01 pm

    In my case I just had to restart the import of the same file 4 times until it started the import again (it skips uploads already imported). Annd worked like a charm.

    • Jordan Schelew on October 8, 2018 at 8:47 pm

      Hey Rafael,

      Great to hear! Are you referring to restarting the import via the WordPress Import UI tool or using the command line? If you’re referring to the UI, I had also noticed that it skips existing items, however the last time I tested it, it had actually duplicated media content every single time I ran it 🙁

      Perhaps that’s fixed now?

      Ultimately I’d love to see the WordPress import utility allow batching so that it can run each batch quicker than standard 45s timeouts without having to re-run things.

  3. kike on August 1, 2018 at 12:22 am

    Is there a way to do this on the CPanel

    • Jordan Schelew on August 7, 2018 at 12:05 pm

      Hey there, using the command line to import with wp-cli should be doable on any platform! You’ll just need to find which PHP path to use for the binary if cPanel has multiple PHP versions installed.

  4. Irshad on April 5, 2018 at 5:19 am

    How to automate the above process? like I am creating a plugin using REST APIs to get product from main store and insert it into other stores or remote servers, the plugin can be use by any person without prior settings on their server.

    • Jordan Schelew on April 6, 2018 at 5:33 pm

      Hey Irshad,

      REST APIs operate through HTTP, so there shouldn’t be a connection to what you want to do and this method of importing XML files from command line. No matter what happens a REST API is going to need to be received by a web server and thusly is subject to that server’s timeout values. That said, you *can* either:

      1. Batch the data stream into smaller segments so that it’s never likely to exceed any given server’s default timeout value, or
      2. If you have access to the server, simply change the HTTP server and its php timeout values

Leave a Comment