How to debug Batch API more efficiently?
Here are some workarounds which I've found so far which makes life easier.

Using curl

You need: drush and curl.


Add var_export($name); exit; into the batch code place of interest, so batch won't be set to finish state.
In the web browser open Network console (e.g. DevTools in Chrome).
Start batch process as usual (in Feeds it's at: /import).
Stop the batch processing just before the redirect by pressing Escape. Then note the URI.



Alternative way is to fetch id directly from the batch table:

$ drush sqlq "SELECT bid FROM batch"

Click on the previous 302 request and take a note of your session cookie from Request Headers, you need only SESS0X=Y cookie, e.g.

Cookie: SESS0F00=B4R

Run curl as below (you need to replace id, session cookie and your host):

$ curl -X POST -d "id=124&amp;op=do" --cookie "SESS0F00=B4R" "http://myhost.local/batch"
your_debug_data_here

Previous step is repeatable after each code change which makes it easy to debug variables in no time.


For ever more efficiently, you can map it (e.g. in vim), so the output can be executed each time when you need it.

Using repeatable XHR requests


Add var_export($name); exit; into the batch code place of interest, so batch won't be set to finish state.
In the web browser open Network console (e.g. DevTools in Chrome).
Start batch process as usual (in Feeds it's at: /import) and it should fail, because of exit; added in step 1.
Note the batch?id=x&amp;op=do request and do Replay XHR (at least in Chrome).
Now on each code change you should be able to repeat the last step over and over again.




There are probably more ways of doing similar thing (including use of some plugins such as Postman, etc).