Drupal: Debug to a file. In a terminal: "tail -f /tmp/drupal.debug"
file_put_contents("/tmp/drupal.debug", print_r($whatever, TRUE), FILE_APPEND);