Search code examples
woocommercetimeoutcsv-import

CSV Import Script stops after a several minutes


I am writing a woocommerce CSV import script. The CSV file has 1000 rows. In my localhost all 1000 rows are creating products in about 40 minutes. But when I upload that script in Hostgator live server it creates about 200 - 300 rows and stops creating products with no errors. I have set set_time_limit(0); but no luck.

It is working fine in localhost but not in live server. So I assume the problem is related to server configuration. Can anybody help me to trace out this problem?


Solution

  • First of all

    max_input_time and set_time_limit(0)

    will only work with VPS or dedicated servers . Instead of that you can follow some rules to your implementation like below

    1. First read the whole CSV file .
    2. Then grab only 10 entries (rows) or less and make a ajax calls to import in DB
    3. Try to call ajax every time with 10 entries and after that echo out something on browser . In this method your script will never timeout .
    4. Follow the same method untill the CSV rows are finished .