Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8307185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:28:36+00:00 2026-06-08T18:28:36+00:00

i have an affliate window CSV which has nearly 1 lac rows, i want

  • 0

i have an affliate window CSV which has nearly 1 lac rows, i want to save this as nodes, and i tried with batch API.

but still i am getting php timeout error ..please help

function MODULE_aw_batch(){  
  $operations = array();
  $csv = file_directory_path().'/aw/datafeed_134642.csv';
  $file = fopen($csv, 'r');
  while (($data = fgetcsv($file)) !== FALSE) {
      $operations[] = array('MODULE_aw_op', array($data));
  }
  $batch = array(
    'title' => t('Generating feeds'), // Title to display while running.
    'operations' => $operations,
    'finished' => 'MODULE_aw_finished', // Last function to call.
    'init_message' => t('Importing...it may take 4-5 hours'),
    'progress_message' => t('Processed @current out of @total.'),
    'error_message' => t('Import feeds has encountered an error.'),
  );
  batch_set($batch);
  batch_process('admin/content/node/overview');
}

update (solved)

instead of reading whole csv file at a time, split the csv to read 5 lines per process

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:28:37+00:00Added an answer on June 8, 2026 at 6:28 pm

    Found the solution

    Batch declaration

    function MODULENAME_batch(){
        $operations[] = array('MODULENAME_op', array()); 
        $batch = array(
            'title' => t('Importing events'),
            'operations' => $operations,
            'finished' => 'MODULENAME_finished',
            'init_message' => t('MESSAGE HERE'),
            'progress_message' => 'MESSAGE HERE',
            'error_message' => t('MESSAGE HERE'),
        );
        batch_set($batch);
        batch_process('admin/content/node/overview');// redirect to this page
    }
    
    function MODULENAME_aw_op(&$context) {      
        if (!isset($context['sandbox']['offset'])) {
            $context['sandbox']['offset'] = 0;
            $context['sandbox']['records'] = 0;
        }
    
        $filename =file_directory_path().'/aw/datafeed_134642.csv'; // csv file
    
        $fp = fopen($filename, 'r');
    
        if ( $fp === FALSE ) {
        // Failed to open file
            watchdog('MODULENAME', 'Failed to open ' . $filename);
            $context['finished'] = TRUE;
            return;
        }
    
        $ret = fseek($fp, $context['sandbox']['offset']);
    
        if ( $ret != 0 ) {
        // Failed to seek
            watchdog('MODULENAME', 'Failed to seek to ' . $context['sandbox']['offset']);
            $context['finished'] = TRUE;
            return;
        }
    
        $limit = 5;  // Maximum number of rows to process at a time
        $done = FALSE;
    
        for ( $i = 0; $i < $limit; $i++ ) {
            $line = fgetcsv($fp);
            if ( $line === FALSE ) {
                $done = TRUE;
                // No more records to process
                break;
            }
            else {          
                $context['sandbox']['records']++;
                $context['sandbox']['offset'] = ftell($fp);
                $record = $context['sandbox']['records'];
                // Do something with the data
    
            }
        }
    
        $eof = feof($fp);
    
        if ( $eof )  {
            $context['success'] = TRUE;
        }
        $context['message'] = "processed " . $context['sandbox']['records'] . " records";
    
        $context['finished'] = ( $eof || $done ) ? 1 : 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have written this little class, which generates a UUID every time an object of
I have a Drupal 5 website on which I want to display a list
Hi I have a site which has a number of affiliate links, I would
Now, I have the following query, which gives me the COUNT() of rows which
I have a Netflix Affiliate account, but I don't want to direct users to
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
Have deployed numerous report parts which reference the same view however one of them
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I want to use Google Shopping Search API for products search. I have followed
I have a product table like this: Product name , Affiliate ID , ProductCode

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.