1

i got an array of items. On each item, a process is executed wich manipulates data, write things to the database,...

When i execute my drush script (ex: drush mycommand) i start a batch process:

$batch = dms_notification_mail_sendout_batch($nid);
batch_set($batch);
$batch =& batch_get();
$batch['progressive'] = FALSE;
drush_backend_batch_process();

Now i was wondering why i would use a batch process here. Does it have any advantages? Because you with drush you don't have to consider PHP timeouts.

In short: If you don't have to consider with PHP timeouts, is batch process still usefull?

Thx!

2

with drush you don't have to consider PHP timeouts.

That's a false assumption. True, timeouts for PHP CLI are usually significantly larger, but they can be set and you can't assume they will not be.

If you own all machines it is supposed to ever run on, that assumption may work at the moment you write your script, but one change in php.ini may cause your scripts to suddenly fail, and that would be a nasty surprise, especially a year or two after you wrote your code, when you will no longer remember where you gave up on using batch processing.

  • i placed max_execution_time on 16s. I did a 20s sleep in my batch operation. But it stil gets executed 'without' an timeout error. – mgoubert Aug 8 '14 at 14:51
  • @Nuctorn Are you sure you set it in the correct php.ini? Also, batch operation means steps are sent to separate processes, so maybe one of them indeed died, and you just haven't noticed? I never bothered to investigate how Drupal's batch works internally. It worked. It allowed execution of "too long" jobs. That was all I needed to know. – Mołot Aug 8 '14 at 14:54
  • midwesternmac.com/blogs/jeff-geerling/… When running PHP from the command line the default setting is 0. I think it is not a good practice to leave it 0. Running php could slow down the server this way. – mgoubert Aug 8 '14 at 15:13
  • @Nuctorn Strange, it worked for me from php.ini - or so I thought. Anyway, thanks for a pointer :) I agree that leaving it 0 may be bad for server's health. Scripts are not daemons that need to stay in background all the time. – Mołot Aug 8 '14 at 15:26
  • 2
    A bigger limitation than the max execution time for Drush script is memory exhaustion. It can be pretty easy to run out of memory, even with memory_limit=-1, if you do a really huge processing job. – greg_1_anderson Aug 8 '14 at 19:33

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.