Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

console.log, console.error for PHP?

Tags:

php

When developing web applications, at the clientside level I use console.log and console.error to help me see what's going on. I am looking for a similar feature at the serverside level to help me see what's going on. I have seen error_log which writes errors to the server's log file and wanted to know if there is a similar function for writing to the servers access logs?

Or am I going about this the wrong way, am I supposed to be using something completely different to see what's going on in the background for serverside development?

like image 209
nami Avatar asked Jul 16 '11 14:07

nami


2 Answers

This worked for me: http://www.paulund.co.uk/output-php-data-in-browser-console

/**
 * Send debug code to the Javascript console
 */ 
function debug_to_console($data) {
  if(is_array($data) || is_object($data)) {
    echo("<script>console.log('PHP: ".json_encode($data)."');</script>");
  } else {
    echo("<script>console.log('PHP: $data');</script>");
  }
}
like image 114
user2961602 Avatar answered Sep 22 '22 06:09

user2961602


It's not quite the same thing, but you might want to investigate the PHP debugger, XDebug.

It has some very powerful debugging features for PHP. For example, you can step through a PHP program line by line and watch where it goes, and what the variables are set to at any given point in the program, etc.

It works best when used in conjunction with an IDE such as Netbeans or Eclipse, as you can use the same interface to debug your programs as you use to edit your code.

It can also generate trace files, which can be loaded into a program called WinCacheGrind, which allows you to trace through the program after it's run, to see, for example, which functions caused it to run slowly.

like image 20
Spudley Avatar answered Sep 18 '22 06:09

Spudley