Discussion:
Mass-Import Process to run in background
Alex Hempton-Smith
2014-04-23 16:32:07 UTC
Permalink
Hi all,

I have large amounts of CSV data (around about 7k rows) to import, each row
being a new post (CPT) and various meta fields.

I can open and print out the contents of the file to the browser fine, but
I just know running that import will time-out.

Within a WordPress plugin, how do a run a large process like that? And even
better, provide some kind of 'percentage complete' feedback to the user?

Thanks,
Alex
Nicholas Ciske
2014-04-23 17:16:01 UTC
Permalink
You break it into chunks -- usually via ajax requests (or meta-refresh if you cant to go old school).

Basically, you make a call to process X rows, that call returns when it's done, you update the % done accordingly, then make the next call to process another X rows.

As long as each call completes within the timeout (be conservative for crappy shared hosting), you just keep hammering away until the import is complete.

The WooCommerce CSV importer is a pretty good model for this (not free, but solid code).

A free plugin model would be an ajax thumbnail tool like:
https://wordpress.org/plugins/ajax-thumbnail-rebuild/


_________________________
Nick Ciske
http://thoughtrefinery.com/
@nciske
Post by Alex Hempton-Smith
Hi all,
I have large amounts of CSV data (around about 7k rows) to import, each row
being a new post (CPT) and various meta fields.
I can open and print out the contents of the file to the browser fine, but
I just know running that import will time-out.
Within a WordPress plugin, how do a run a large process like that? And even
better, provide some kind of 'percentage complete' feedback to the user?
Thanks,
Alex
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Jaime Martínez
2014-04-24 17:23:06 UTC
Permalink
Hi Alex,

I sugest you use http://wp-cli.org and look at existing code like the wp user import-csv, wp post create or wp media regenerate for inspiration.

You can create an custom command that runs your code from the commandline. No time-outs :)

Saves time building an interface.

Ciao,

Jaime
Post by Alex Hempton-Smith
Hi all,
I have large amounts of CSV data (around about 7k rows) to import, each row
being a new post (CPT) and various meta fields.
I can open and print out the contents of the file to the browser fine, but
I just know running that import will time-out.
Within a WordPress plugin, how do a run a large process like that? And even
better, provide some kind of 'percentage complete' feedback to the user?
Thanks,
Alex
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Loading...