WP All Import cron from CLI

The WP All Import plugin can be used to import data from xml feeds. We use it in combination with WooCommerce. To automatically update your products and/or stock information, you should run this from a cron job. Unfortunately WP All Import didn’t do a very nice job on integrating this with the WordPress cron system, because I feel that the scheduling should be manager from your WordPress install instead of cronjob settings on the server.

WP All Import suggests that you set a cron job where you request an URL with wget. They already noticed a possible issue with this approach, which is timeouts. Therefore they created two actions: one to trigger the import, and a second one to process the import. When a timeout occurs, the process action should continue where it left of.

In our situation (nginx + php-fpm) this didn’t seem to work very well. The script was aborted after 30 seconds (which is what we have configured on the server ourselves), but when I re-requested the processing action, it said I should run the trigger action first. So, did the processing complete or not?

Since I don’t like running web requests from cron anyways, I searched for a method to run the import with PHP cli. This way we don’t have timeouts and the script will execute nicely. Also you can skip the “The processing URL should be run every two minutes because it may not finish your import in one run.” because it’s very unlikely that the script will timeout.

Enough chichat, here’s the line I added to /etc/cron.d/mywebshop:

Don’t forget to change the path to your WordPress install, and the import_key.

8 thoughts on “WP All Import cron from CLI

    • Dave, although this seems like an advertisement to me, I guess easycron could be a nice tool. But the cron jobs are still executed through the webserver, and that’s exactly the problem with WP All Import. Easy cron will not solve this. Executing the job with php cli will.

  1. rolandow thanks so much for this, was looking long and hard for a solution, just a few questions. If we have multiple imports would we just add the other ones below the first line, and second what if we want an email to be sent when completed ? also does this method keep logs anywhere ? because with wpallimports method the users home directory filled up with hundreds of logs
    thanks in advance
    John

  2. Pingback: WP All Import cron from CLI (update) - Rolandow's dev blogRolandow's development blog

Leave a Reply

Your email address will not be published. Required fields are marked *