2

Do PHP static variables, which do persist during a normal page request, persist between progressive Batch API runs? What about during non-progressive (command-line) batch execution? Does &drupal_static come into play in any way?

In my application, I want to take advantage of in-memory caching across batch processes.

3

No they do not.

I had a similar question some time ago: https://drupal.stackexchange.com/a/59274/1899

PHP static variables do not persist between requests.

In your batch operation, you receive an array argument as the last argument. Call it &$context (pass by reference), and then you can have persistent variables.

  • $context['sandbox'] preserved between iterations of the same batch task. Useful for progressive batch OPs.

  • $context['results'] preserved throughout the entire batch progress.

4

Static variables exist per request, so no, they won't persist across separate batch runs.

If you need to cache data across requests in memory just use redis/memcache/etc, there are contrib modules available for each that hook into the core caching stays so you can use a familiar API

  • I'd like to give you both credit for the most correct answers, because both were very helpful. However, I am giving the littler points more points, because it's the New Year, and I still feel Christmas. – texas-bronius Jan 4 '16 at 20:24

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.