简体   繁体   中英

PHP error_log() isn't working

I'm working on a basic app that doesn't use any framework, and no debug = 1 . I'm trying to figure out how to show php's var_dump s and error_log s, but I'm not sure where they are supposed to be printed.

I'm using PHP's built-in server at localhost. Here is my html:

<?php

session_start();

?>

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>

    <pre>

    </pre>  

</body>
</html>

I thought session_start() would have the php var_dump s show before the html, but there isn't anything.

I also tried installing ChromePHP, I could get it to print things in the HTML, but not when I moved the statements into the PHP code.

I also have this class logging some errors:

class Utils {

    public static function log($message)
    {
        @error_log($message, 0);
    }

}

I tried changing it to error_log($message, 3, './mylog.txt') ; still nothing.

This is probably the most basic question ever written, but I have no idea how to debug plain PHP.

Beside session_start() there is no PHP-Command in your code. No echo, no var_dump... and session_start is written correctly. What PHP does in that case is starting the session and return the rest of your Html-Code to the browser.

So there is no real problem here.

If you want to see something,

// you should try
echo "Test, PHP is working";

If you don't see anything here, then your Webserver doesn't work properly. Look into which port you should use and see whether the service is running.

In case you have further code which you want to debug, there are some commands to define the output.

// Look up those:
ini_set("display_errors", 1);
ini_set("track_errors", 1);
ini_set("html_errors", 1);
error_reporting(E_ALL);

Does this help?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM