简体   繁体   中英

sync mysql DB with xml file

  1. I have wordpress page (along with mysql db with wp tables.
  2. I have custom table in DB named "custom_table"

What I need is to add functionality to upload xml file on wordpress page and then sync my custom_table with this xml so the table reflects xml file.

XML file size is now ~6MB but I guess it might grow in the future. During syncing custom_table has to be intact - I mean that changes to the table during syncing have to be atomic - all or nothing.

It is a good idea to do this in normal php script or I should better make some background job for this stuff? For example upload xml file to server and then run in background a job which will parse xml file and put to DB?

6MB is a lot when you are dealing with a slow internet connection and with a script that has a chance of timing out.

I see 3 issues that you are trying to solve here -

  1. Long running processes - background jobs are perfect for this. You can cut off the user session using pcnt_fork() or by just closing the session and then continuing the processing. Ensure that your max_execution time is set to 0 or sufficiently long.
  2. Atomicity - ACID is a main feature of the InnoDB format. Create your table as InnoDB instead of MyISAM.
  3. Completion - you will need to keep track of success/failure. Background jobs are difficult to debug. As you are working with Wordpress, I'm assuming that you are on a shared host? You can try adding statements at appropriate locations in your code that will send you an email or use system logging if that's available to you. Another way would be to have a separate table for logs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM