I decided to write my own csv node importer since Feeds did not give me the functionality I needed. I have about 500 nodes to create each month and from that node it needs to create another node.

I have everything working right for a few nodes, however for 500 I get a 'page not found'. I want to echo out 'Node $nodeID created' so the users knows the script is working. I tried ob_start but I can't seem to get it to keep echoing out the result.

Does anyone have a better solution?

Here is a simple snippet:

 $file_handle = fopen("FinalListToIMport.csv", "r");

 $i = 0;
  while (!feof($file_handle) ) {

    $row = fgetcsv($file_handle, 100024);
    if($i != 0 && $row[0] != ''){
        $update_node = node_load($nid);
        $update_node->title = 'update title';
       echo('Node: '.$row[0].'updated');


  • could you post the code? – Mohammed Shameem Jan 18 '13 at 18:03
  • Here is a simple snippet: – Brian Jan 18 '13 at 18:19
  • forgot the code i guess... – Mohammed Shameem Jan 18 '13 at 18:20
  • Just added it to the regular post, sorry – Brian Jan 18 '13 at 18:22
  • could paste the one with ob_start that did not work for you... – Mohammed Shameem Jan 18 '13 at 18:24

You can use the drupal_set_message() to send a feedback to the user. It's the best way to do that in my opinion.


In order to prevent the timeout issue you must use Drupal's Batch API.

Here goes another example: https://gist.github.com/4329270

  • Drupal Set message might not be the way to go as the script is exceeding the execution time and hence the page not found error. – Mohammed Shameem Jan 18 '13 at 18:50
  • I totally agree with the batch process. But he still should use Drupal's API to send the message. – revagomes Jan 18 '13 at 19:03
  • I don't know why this was downvoted but revagomes has my upvote :) also, @Brian, make sure that you check that the node actually exists before you call node_save(). and a tip: you can load multiple nodes using node_load_multiple(). – AyeshK Jan 18 '13 at 20:08

Since this is running a long script I would suggest looking at the example module.

There is a module with in that called batch_example

That explains how you can put a progress bar or in your case the node id as the script progress.


I did this while back just as Shameem suggested, custom code using Batching so there would not be any memory problems.

Alternatively you could try going back to Feeds and use module Feeds Tamper http://drupal.org/project/feeds_tamper which lets you alter the data a bit on the way in.

  • I did use feeds however I needed a cck field set as my unique target and it would not let me. I would love to use feeds again if I could figure out how to flag that field as unique. – Brian Jan 18 '13 at 23:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.