1

I know that this question is been already asked a lot of times in this forum, but everything that i've tried didn't work. I usually use safari and i want to know how to print in the safari console. I work directly on the ftp server so i can't install anything into program like mamp. I use safari but if you know a solution for another browser i'm happy to try it.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
D. belvedere
  • 45
  • 2
  • 8
  • 2
    What did you try that didn't work? You have to print to the console via JS, but you can generate the data to be printed in your PHP script. – Michael Mior Dec 02 '17 at 21:23
  • 3
    You print to the browser console in JavaScript, not in PHP. I suppose your PHP code could simply emit JavaScript code which prints to the console. For example: `echo "";` – David Dec 02 '17 at 21:23

1 Answers1

3

Unlike Javascript, which runs in a virtual machine in your browser, PHP runs on the remote machine. Unless you take pains to set up remote debugging, PHP does not have any secret channel to your workstation where you are coding. JetBrains has a nice IDE and offers documentation on how to set up this secret communication channel so you can step through code. It's fairly involved.

Eclipse PDT is what I use and it also has a fairly elaborate setup.

If you just want to write messages that you can inspect to check values and stuff--something like console.log, I suggest that you write a logging function that writes to a file. Something like this:

function my_log($msg) {
    // consider changing this log file's location to something else
    if (!file_put_contents("/tmp/my-log-file.txt", "[" . date("Y-m-d H:i:s") . "] " . $msg . "\n", FILE_APPEND)) {
        die("Unable to write log file!");
    }
}

Note that if you are running your PHP scripts via a web server, then the web server user will need permission to write the file. On Debian/Ubuntu machines, the apache user is www-data. On Red Hat/CentOs machines, I think it is apache. You can find out which user the web server runs as by putting this script on your server and loading it in your browser:

<?php
passthru("whoami");

My instructions here assume you are working on a *nix machine. If you're running windows, we might have to dig a little deeper.

S. Imp
  • 2,833
  • 11
  • 24