Book Image

Drush for Developers - Second Edition

By : Juan Pablo Novillo Requena, Juan P Novillo Requena
Book Image

Drush for Developers - Second Edition

By: Juan Pablo Novillo Requena, Juan P Novillo Requena

Overview of this book

Table of Contents (13 chapters)
Drush for Developers Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
2
Keeping Database Configuration and Code Together
Index

Running long tasks in batches


There might be times where a task (for example, a Drush command or a PHP script) might take so long to complete that it hits one of PHP's constraints such as memory_limit, max_execution_time, or max_input_vars. In these cases, when you foresee that a task might take a considerable amount of time or resources to complete, it is safer to split the work into chunks that can be completed in smaller, independent, and consecutive processes. This is what Drupal's Batch API (https://www.drupal.org/node/180528) is for. In this section, we will explain how it works and examine how a contributed module uses it in order to complete a large task safely.

The most common errors we might find during a long process are:

  • Allowed memory size of [some number] bytes exhausted: This means that our script attempted to use more memory than the maximum allowed to PHP at the memory_limit setting.

  • Fatal error: Maximum execution time of 30 seconds exceeded: This means that our script took...