new: json_encode_stack(): workaround for resources in arg lists (cannot be handled by json_encode())
need more locks
rewrite debug, error logic
- store early debug data in $sql_delayed_inserts['debug_raw'], reprocess later
- handle conditional debugging right: upper limit on cound, $debug_requests, by-pass for errors