0

So I am using xampp as my server hosting, and haven't got a problem in years. But I found something strange happening.

I have this code:

require "init.php";
require_once('vendor/autoload.php');

$pdf = new TCPDF("P", "mm", 'A4', true, 'UTF-8', false);

var_dump($pdf);

If I execute this code. My page is fully blank? And sometimes it isn't. Like so:

enter image description here

But when I execute my page in a command line, like so:

c:\xampp\php\php.exe C:\xampp\htdocs\websites\Traject-Parket\index.php

I get the var_dump I wrote.

enter image description here

So I have no errors whats so ever? How come my page is blank and sometimes isn't? Because in this project nothing seems to work but in other projects it does.

Mark_
  • 113
  • 1
  • 12
  • 1
    Do you have any errors in your logs when you are running your PHP from your browser ? – Nicolas Dec 20 '19 at 13:52
  • Check if the local php configuration is correct, maybe installing a newer version off that program maybe that helps – Raymond Nijland Dec 20 '19 at 13:54
  • Also check `phpinfo()` (through the web server) and then `php -v` from the command line to make sure they are using the same PHP version. – M. Eriksson Dec 20 '19 at 13:55
  • @Nicolas Is their a tool for that? – Mark_ Dec 20 '19 at 14:05
  • @RaymondNijland It is, I have the latest versions – Mark_ Dec 20 '19 at 14:06
  • @MagnusEriksson It's the same – Mark_ Dec 20 '19 at 14:06
  • 1
    @Mark_ Usually it's in a file somewhere. a quick google search got me [this answer](https://stackoverflow.com/questions/3719549/where-does-phps-error-log-reside-in-xampp) – Nicolas Dec 20 '19 at 14:06
  • @Nicolas Okay I found something interesting, I get this: [Fri Dec 20 15:09:59.038835 2019] [php7:error] [pid 10640:tid 1892] [client ::1:55357] PHP Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 4096 bytes) in C:\\xampp\\htdocs\\websites\\Traject-Parket\\vendor\\tecnickcom\\tcpdf\\tcpdf.php on line 8147 – Mark_ Dec 20 '19 at 14:10
  • It looks like xampp is not getting enough RAM. could you check in your php.ini and increase the `memory_limit ` value – Nicolas Dec 20 '19 at 14:12
  • check the memory limits in both your php.ini and your php-cli.ini – delboy1978uk Dec 20 '19 at 14:12
  • 1
    This is working in cli because xampp and Cli does not have the same php.ini file. – Nicolas Dec 20 '19 at 14:13
  • kind of what i just said :-P – delboy1978uk Dec 20 '19 at 14:16
  • I increased the memory limit, it was on default "128M" and I set it to like 518M and nothing changed, So I set even higher but still same error log? How much should I set it? And I don't have a php-cli.ini file. – Mark_ Dec 20 '19 at 14:21
  • 1
    Okay update, I added this code: ini_set('memory_limit', '-1'); to the top of my page and it works! But maybe this isn't the cleanest way is it? And I want this to be hosted on a different server later or soon, will that cause problems? – Mark_ Dec 20 '19 at 14:24

2 Answers2

0

Blank pages (or WSOD, white screen of death) is when your script fails. You don;'t have display_errors turned on, so at the top of your script, you can say:

ini_set('display_errors', true);
error_reporting(-1);

And that will allow you to see the error.

However, it isn't the best way. Error logging directly to the screen not onl;y distorts your page, but can ruin header() calls, as the HTTP body has already started outputting and thus no more HTTP headers can come out.

For the best error logging experience, set error_reporting to -1, turn display_errors off, and set a custom error_log. Then in the terminal, type tail -f /path/to/error_log. Your notices, warnings and errors will now scroll past in real time, without distorting your web page's display.

delboy1978uk
  • 12,118
  • 2
  • 21
  • 39
  • 1
    This is a good answer, however i'm not sur if it answer OP's question. if you look at [this comment](https://stackoverflow.com/questions/59426313/blank-page-on-php-7-3-9-using-xampp-3-2-4?noredirect=1#comment105039294_59426313) it looks like a memory issue rather than an error logging one. – Nicolas Dec 20 '19 at 14:14
  • 1
    Of course it does. He's asking about a white screen! Now he has found his error, but he hasn't updated his question, so it remains, why is this page blank? – delboy1978uk Dec 20 '19 at 14:15
  • 1
    Youre right! This fixed my problem on finding my error. Thanks! And ofcourse the rest of you guys – Mark_ Dec 20 '19 at 14:25
  • like i say, learn to tail the log rather than use display_errors though, you'll thank yourself! – delboy1978uk Dec 20 '19 at 14:27
0

I don't know this library, but var_dump shows that unprotected data from PHP 5.6.0.

Maybe the problem comes from there?

Look at the __debugInfo() method

And give us the exit.

mattig
  • 1
  • 1